View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.data;
17  
18  import java.io.Serializable;
19  
20  import javax.persistence.Version;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.rice.core.api.mo.common.GloballyUnique;
24  
25  
26  /**
27   * CopyOption is used when calling the {@link DataObjectService#copyInstance(Object)} method to adjust the behavior of
28   * the method.
29   * 
30   * See the constants defined within the class for the available options and descriptions.
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class CopyOption implements Serializable {
35  	private static final long serialVersionUID = 1L;
36  
37      /**
38  	 * Specify that the PK fields on the object must be cleared as part of the copy operation.
39  	 */
40  	public static CopyOption RESET_PK_FIELDS = new CopyOption("org.kuali.rice.krad.data.RESET_PK_FIELDS");
41  
42  	/**
43  	 * Specify that the {@link Version} annotated field should be cleared if present on the copied object.
44  	 */
45  	public static CopyOption RESET_VERSION_NUMBER = new CopyOption("org.kuali.rice.krad.data.RESET_VERSION_NUMBER");
46  
47  	/**
48  	 * Specify that the {@literal <tt>objectId</tt>} field (see {@link GloballyUnique}) should be cleared on the copied
49  	 * object and all children.
50  	 */
51  	public static CopyOption RESET_OBJECT_ID = new CopyOption("org.kuali.rice.krad.data.RESET_OBJECT_ID");
52  
53      private final String optionId;
54  
55  	/**
56  	 * Sets the option Id
57  	 * 
58  	 * @param optionId
59  	 *            cannot be null or blank.
60  	 */
61      public CopyOption(String optionId) {
62          if (StringUtils.isBlank(optionId)) {
63              throw new IllegalArgumentException("optionId must not be a null or blank value");
64          }
65          this.optionId = optionId;
66      }
67  
68  	/**
69  	 * Gets the option id.
70  	 * 
71  	 * @return not null or blank.
72  	 */
73      public String getOptionId() {
74          return this.optionId;
75      }
76  
77  	@Override
78  	public String toString() {
79  		return optionId;
80  	}
81  }