/** * Creates a new business object data attribute entity from the business object data entity and * the request information. * * @param businessObjectDataEntity the business object data entity * @param request the business object data attribute create request * @return the newly created business object data attribute entity */ private BusinessObjectDataAttributeEntity createBusinessObjectDataAttributeEntity( BusinessObjectDataEntity businessObjectDataEntity, BusinessObjectDataAttributeCreateRequest request) { // Create a new entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setBusinessObjectData(businessObjectDataEntity); businessObjectDataAttributeEntity.setName( request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName()); businessObjectDataAttributeEntity.setValue(request.getBusinessObjectDataAttributeValue()); return businessObjectDataAttributeEntity; }
/** * Creates a new business object data attribute. * * @param request the information needed to create a business object data attribute * @return the newly created business object data attribute */ @Override public BusinessObjectDataAttribute createBusinessObjectDataAttribute( BusinessObjectDataAttributeCreateRequest request) { // Validate and trim the key. dmHelper.validateBusinessObjectDataAttributeKey(request.getBusinessObjectDataAttributeKey()); // If namespace is not specified, get the namespace code by locating the legacy business object // definition. if (StringUtils.isBlank(request.getBusinessObjectDataAttributeKey().getNamespace())) { request .getBusinessObjectDataAttributeKey() .setNamespace( dmDaoHelper.getNamespaceCode( request.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName())); } // Get the business object format and ensure it exists. BusinessObjectFormatEntity businessObjectFormatEntity = dmDaoHelper.getBusinessObjectFormatEntity( new BusinessObjectFormatKey( request.getBusinessObjectDataAttributeKey().getNamespace(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion())); // Validate the attribute value. if (dmDaoHelper.isBusinessObjectDataAttributeRequired( request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectFormatEntity)) { Assert.hasText( request.getBusinessObjectDataAttributeValue(), String.format( "A business object data attribute value must be specified since \"%s\" is a required attribute for business object format {%s}.", request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), dmDaoHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity))); } // Get the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = dmDaoHelper.getBusinessObjectDataEntity( new BusinessObjectDataKey( request.getBusinessObjectDataAttributeKey().getNamespace(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion(), request.getBusinessObjectDataAttributeKey().getPartitionValue(), request.getBusinessObjectDataAttributeKey().getSubPartitionValues(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDataVersion())); // Load all existing business object data attribute entities into a map for quick access using // lowercase attribute names. Map<String, BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntityMap = dmDaoHelper.getBusinessObjectDataAttributeEntityMap( businessObjectDataEntity.getAttributes()); // Ensure a business object data attribute with the specified name doesn't already exist for the // specified business object data. if (businessObjectDataAttributeEntityMap.containsKey( request .getBusinessObjectDataAttributeKey() .getBusinessObjectDataAttributeName() .toLowerCase())) { throw new AlreadyExistsException( String.format( "Unable to create business object data attribute with name \"%s\" because it already exists for the the business object data {%s}.", request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), dmDaoHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity))); } // Create a business object data attribute entity from the request information. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = createBusinessObjectDataAttributeEntity(businessObjectDataEntity, request); // Persist the new entity. businessObjectDataAttributeEntity = dmDao.saveAndRefresh(businessObjectDataAttributeEntity); // Create and return the business object data attribute object from the persisted entity. return createBusinessObjectDataAttributeFromEntity(businessObjectDataAttributeEntity); }