Java tutorial
/* * Kuali Coeus, a comprehensive research administration system for higher education. * * Copyright 2005-2015 Kuali, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.kuali.kra.award.awardhierarchy.sync.helpers; import org.apache.commons.lang3.StringUtils; import org.kuali.kra.award.awardhierarchy.sync.AwardSyncChange; import org.kuali.kra.award.awardhierarchy.sync.AwardSyncType; import org.kuali.kra.award.contacts.AwardPerson; import org.kuali.kra.award.home.Award; import org.kuali.rice.krad.bo.PersistableBusinessObject; import java.lang.reflect.InvocationTargetException; import java.util.Collection; /** * * Award Hierarchy Sync Helper for AwardPersons. */ public class AwardSyncPersonHelper extends AwardSyncHelperBase { @SuppressWarnings("unchecked") @Override public void applySyncChange(Award award, AwardSyncChange change) throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, InstantiationException { Collection awardPersons = award.getProjectPersons(); AwardPerson person = (AwardPerson) getAwardSyncUtilityService().findMatchingBo(awardPersons, change.getXmlExport().getKeys()); if (StringUtils.equals(change.getSyncType(), AwardSyncType.ADD_SYNC.getSyncValue())) { if (person != null) { this.setValuesOnSyncable(person, change.getXmlExport().getValues(), change); } else { person = new AwardPerson(); setValuesOnSyncable(person, change.getXmlExport().getKeys(), change); setValuesOnSyncable(person, change.getXmlExport().getValues(), change); award.add(person); } } else { if (person != null) { awardPersons.remove(person); } } } @Override protected String getObjectDesc(PersistableBusinessObject syncableObject, String attrName) { AwardPerson person = (AwardPerson) syncableObject; return person.getContactRole().getRoleDescription(); } @Override protected String getDataDesc(PersistableBusinessObject syncableObject, String attrName) { AwardPerson person = (AwardPerson) syncableObject; return person.getFullName(); } }