1 /*
2 * Copyright 2011 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.osedu.org/licenses/ECL-2.0
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.student.mock.utilities;
17
18
19 import java.util.Date;
20
21 import org.kuali.student.r2.common.dto.MetaInfo;
22 import org.kuali.student.r2.common.infc.*;
23
24
25 /**
26 * A helper class for the Mock implementation
27 * @author nwright
28 */
29 public class MockHelper {
30
31 /**
32 * Create a new MetaInfo with the create id and time as well as the update
33 * date and time and version ind set
34 * @param context
35 * @return
36 */
37 public MetaInfo createMeta(Context context) {
38 MetaInfo mInfo = MetaInfo.newInstance();
39 Date now = new Date();
40 mInfo.setCreateId(context.getPrincipalId());
41 mInfo.setCreateTime(now);
42 mInfo.setUpdateId(context.getPrincipalId());
43 mInfo.setUpdateTime(now);
44 mInfo.setVersionInd("1");
45 return mInfo;
46 }
47
48 /**
49 * Updates the MetaInfo with new user id and date stamp
50 * Also increments the verssion indicator
51 * @param orig
52 * @param context
53 * @return new metainfo
54 */
55 public MetaInfo updateMeta(Meta orig, Context context) {
56 Date now = new Date();
57 int oldVersionInd = Integer.parseInt(orig.getVersionInd());
58 MetaInfo mInfo = MetaInfo.getInstance(orig);
59 mInfo.setUpdateId(context.getPrincipalId());
60 mInfo.setUpdateTime(now);
61 mInfo.setVersionInd("" + (oldVersionInd + 1));
62 return mInfo;
63 }
64
65
66
67 }
68