/** * @see org.kuali.rice.krad.bo.GlobalBusinessObject#isPersistable() returns whether this global * object reversion can be stored in the database, which is really a question of whether it * and all of its details have all of their appropriate primary keys set. */ public boolean isPersistable() { PersistenceStructureService persistenceStructureService = SpringContext.getBean(PersistenceStructureService.class); if (!persistenceStructureService.hasPrimaryKeyFieldValues(this)) { return false; } for (OrganizationReversionGlobalDetail orgRevDetail : this.getOrganizationReversionGlobalDetails()) { if (!persistenceStructureService.hasPrimaryKeyFieldValues(orgRevDetail)) { return false; } } for (OrganizationReversionGlobalOrganization orgRevOrg : this.getOrganizationReversionGlobalOrganizations()) { if (!persistenceStructureService.hasPrimaryKeyFieldValues(orgRevOrg)) { return false; } } // are we still here? really? Then, hey, let's persist! return true; }
@Override public void refreshReferenceObject( PersistableBusinessObject businessObject, String referenceObjectName) { if (StringUtils.isNotBlank(referenceObjectName) && !StringUtils.equals(referenceObjectName, "extension")) { if (persistenceStructureService.hasReference(businessObject.getClass(), referenceObjectName) || persistenceStructureService.hasCollection( businessObject.getClass(), referenceObjectName)) { retrieveReferenceObject(businessObject, referenceObjectName); } } }
/** This method is for refreshing References of Origin Entry */ protected void refreshOriginEntryReferences(OriginEntryFull originEntry) { Map<String, Class> referenceClasses = persistenceStructureService.listReferenceObjectFields(originEntry.getClass()); for (String reference : referenceClasses.keySet()) { if (KFSPropertyConstants.PROJECT.equals(reference)) { if (KFSConstants.getDashProjectCode().equals(originEntry.getProjectCode())) { originEntry.setProject(null); } else { persistenceService.retrieveReferenceObject(originEntry, reference); } } else if (KFSPropertyConstants.FINANCIAL_SUB_OBJECT.equals(reference)) { if (KFSConstants.getDashFinancialSubObjectCode() .equals(originEntry.getFinancialSubObjectCode())) { originEntry.setFinancialSubObject(null); } else { persistenceService.retrieveReferenceObject(originEntry, reference); } } else if (KFSPropertyConstants.SUB_ACCOUNT.equals(reference)) { if (KFSConstants.getDashSubAccountNumber().equals(originEntry.getSubAccountNumber())) { originEntry.setSubAccount(null); } else { persistenceService.retrieveReferenceObject(originEntry, reference); } } else { persistenceService.retrieveReferenceObject(originEntry, reference); } } }
@SuppressWarnings("unchecked") @Override public List<String> listPrimaryKeyFieldNames(Class<?> type) { List<String> keys = new ArrayList<String>(); if (type == null) { return keys; } if (isPersistable(type)) { keys = persistenceStructureService.listPrimaryKeyFieldNames(type); } else { ModuleService responsibleModuleService = kualiModuleService.getResponsibleModuleService(type); if (responsibleModuleService != null && responsibleModuleService.isExternalizable(type)) { keys = responsibleModuleService.listPrimaryKeyFieldNames(type); } else { // check the Data Dictionary for PK's of non PBO/EBO DataObjectEntry dataObjectEntry = dataDictionaryService.getDataDictionary().getDataObjectEntry(type.getName()); if (dataObjectEntry != null) { List<String> pks = dataObjectEntry.getPrimaryKeys(); if (pks != null) { keys = pks; } } else { LOG.warn( "Unable to retrieve data object entry for non-persistable KNS-managed class: " + type.getName()); } } } return keys; }
@Override public PersistableBusinessObjectExtension getExtension( Class<? extends PersistableBusinessObject> businessObjectClass) throws InstantiationException, IllegalAccessException { Class<? extends PersistableBusinessObjectExtension> extensionClass = persistenceStructureService.getBusinessObjectAttributeClass( businessObjectClass, "extension"); if (extensionClass != null) { return extensionClass.newInstance(); } return null; }
/** * get the relationship metadata for the detail line fields * * @return the relationship metadata for the detail line fields */ public Map<String, DataObjectRelationship> getRelationshipMetadata() { LOG.debug("getRelationshipMetadata() start"); PersistenceStructureService persistenceStructureService = SpringContext.getBean(PersistenceStructureService.class); Map<String, DataObjectRelationship> relationshipMetadata = new HashMap<String, DataObjectRelationship>(); for (String attributeName : this.getInquirableFieldNames()) { Map<String, Class<? extends BusinessObject>> primitiveReference = LookupUtils.getPrimitiveReference(newDetailLine, attributeName); if (primitiveReference != null && !primitiveReference.isEmpty()) { DataObjectRelationship primitiveRelationship = this.getPrimitiveDataObjectRelationship( persistenceStructureService.getRelationshipMetadata( newDetailLine.getClass(), attributeName)); relationshipMetadata.put(attributeName, primitiveRelationship); } } return relationshipMetadata; }
@Override public Class<?> determineCollectionObjectType( Class<?> containingType, String collectionPropertyName) { final Class<?> collectionObjectType; if (isPersistable(containingType)) { Map<String, Class> collectionClasses = new HashMap<String, Class>(); collectionClasses = persistenceStructureService.listCollectionObjectTypes(containingType); collectionObjectType = collectionClasses.get(collectionPropertyName); } else { throw new RuntimeException( "Can't determine the Class of Collection elements because persistenceStructureService.isPersistable(" + containingType.getName() + ") returns false."); } return collectionObjectType; }
@Override public Class<?> getExtensionAttributeClass(Class<?> boClass, String attributePropertyName) { return persistenceStructureService.getBusinessObjectAttributeClass( (Class<? extends PersistableBusinessObject>) boClass, attributePropertyName); }
@Override public boolean isPersistable(Class<?> dataObjectClass) { return persistenceStructureService.isPersistable(dataObjectClass); }
@Override public Map<String, Class> listCollectionObjectTypes(Class<?> type) { return persistenceStructureService.listCollectionObjectTypes(type); }
@Override public boolean isCollectionUpdatable(Class<?> type, String collectionName) { return persistenceStructureService.isCollectionUpdatable(type, collectionName); }
@SuppressWarnings("rawtypes") @Override public Map<String, Class> listReferenceObjectFields(Class<?> type) { return persistenceStructureService.listReferenceObjectFields(type); }
@Override public boolean isReferenceUpdatable(Class<?> type, String referenceName) { return persistenceStructureService.isReferenceUpdatable(type, referenceName); }
@Override public ForeignKeyFieldsPopulationState getForeignKeyFieldsPopulationState( Object dataObject, String referenceName) { return persistenceStructureService.getForeignKeyFieldsPopulationState( (PersistableBusinessObject) dataObject, referenceName); }
@Override public Map<String, String> getForeignKeysForReference(Class<?> clazz, String attributeName) { return persistenceStructureService.getForeignKeysForReference(clazz, attributeName); }
@Override public boolean hasPrimaryKeyFieldValues(Object dataObject) { return persistenceStructureService.hasPrimaryKeyFieldValues(dataObject); }
@Override public boolean hasCollection(Class<?> boClass, String collectionName) { return persistenceStructureService.hasCollection(boClass, collectionName); }
@Override public boolean hasReference(Class<?> boClass, String referenceName) { return persistenceStructureService.hasReference(boClass, referenceName); }