1 /**
2 * Copyright 2005-2013 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.krms.util;
17
18 import org.kuali.rice.core.api.util.RiceKeyConstants;
19 import org.kuali.rice.krad.bo.GlobalBusinessObject;
20 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.util.KRADConstants;
23 import org.kuali.student.common.uif.rule.KsMaintenanceDocumentRuleBase;
24
25 /**
26 * This class contains the rules for the AgendaEditor.
27 *
28 * @author Kuali Student Team
29 */
30 public class RuleEditorBusRule extends KsMaintenanceDocumentRuleBase {
31
32 @Override
33 protected boolean primaryKeyCheck(MaintenanceDocument document) {
34 // default to success if no failures
35 boolean success = true;
36 Class<?> dataObjectClass = document.getNewMaintainableObject().getDataObjectClass();
37
38 // Since the dataObject is a wrapper class we need to return the agendaBo instead.
39 Object oldBo = document.getOldMaintainableObject().getDataObject();
40 Object newDataObject = document.getNewMaintainableObject().getDataObject();
41
42 // We dont do primaryKeyChecks on Global Business Object maintenance documents. This is
43 // because it doesnt really make any sense to do so, given the behavior of Globals. When a
44 // Global Document completes, it will update or create a new record for each BO in the list.
45 // As a result, there's no problem with having existing BO records in the system, they will
46 // simply get updated.
47 if (newDataObject instanceof GlobalBusinessObject) {
48 return success;
49 }
50
51 // fail and complain if the person has changed the primary keys on
52 // an EDIT maintenance document.
53 if (document.isEdit()) {
54 if (!KRADServiceLocatorWeb.getLegacyDataAdapter().equalsByPrimaryKeys(oldBo, newDataObject)) {
55 // add a complaint to the errors
56 putDocumentError(KRADConstants.DOCUMENT_ERRORS,
57 RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_PRIMARY_KEYS_CHANGED_ON_EDIT,
58 getHumanReadablePrimaryKeyFieldNames(dataObjectClass));
59 success &= false;
60 }
61 }
62
63 return success;
64 }
65
66 @Override
67 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
68 return true;
69 }
70
71 }
72