use of com.runwaysdk.dataaccess.metadata.MdAttributeGraphReferenceDAO in project geoprism-registry by terraframe.
the class BusinessType method apply.
@Transaction
public static BusinessType apply(JsonObject object) {
String code = object.get(BusinessType.CODE).getAsString();
String organizationCode = object.get(BusinessType.ORGANIZATION).getAsString();
Organization organization = Organization.getByCode(organizationCode);
ServiceFactory.getGeoObjectTypePermissionService().enforceCanCreate(organization.getCode(), false);
if (!MasterList.isValidName(code)) {
throw new InvalidMasterListCodeException("The geo object type code has an invalid character");
}
if (code.length() > 64) {
// Setting the typename on the MdBusiness creates this limitation.
CodeLengthException ex = new CodeLengthException();
ex.setLength(64);
throw ex;
}
// assignSRAPermissions(mdVertex, mdBusiness);
// assignAll_RA_Permissions(mdVertex, mdBusiness, organizationCode);
LocalizedValue localizedValue = LocalizedValue.fromJSON(object.get(DISPLAYLABEL).getAsJsonObject());
BusinessType businessType = (object.has(OID) && !object.get(OID).isJsonNull()) ? BusinessType.get(object.get(OID).getAsString()) : new BusinessType();
businessType.setCode(code);
businessType.setOrganization(organization);
LocalizedValueConverter.populate(businessType.getDisplayLabel(), localizedValue);
boolean isNew = businessType.isNew();
if (isNew) {
MdVertexDAO mdVertex = MdVertexDAO.newInstance();
mdVertex.setValue(MdGeoVertexInfo.PACKAGE, RegistryConstants.BUSINESS_PACKAGE);
mdVertex.setValue(MdGeoVertexInfo.NAME, code);
mdVertex.setValue(MdGeoVertexInfo.ENABLE_CHANGE_OVER_TIME, MdAttributeBooleanInfo.FALSE);
mdVertex.setValue(MdGeoVertexInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
LocalizedValueConverter.populate(mdVertex, MdVertexInfo.DISPLAY_LABEL, localizedValue);
mdVertex.apply();
// TODO CREATE the edge between this class and GeoVertex??
MdVertexDAOIF mdGeoVertexDAO = MdVertexDAO.getMdVertexDAO(GeoVertex.CLASS);
MdAttributeGraphReferenceDAO mdGeoObject = MdAttributeGraphReferenceDAO.newInstance();
mdGeoObject.setValue(MdAttributeGraphReferenceInfo.REFERENCE_MD_VERTEX, mdGeoVertexDAO.getOid());
mdGeoObject.setValue(MdAttributeGraphReferenceInfo.DEFINING_MD_CLASS, mdVertex.getOid());
mdGeoObject.setValue(MdAttributeGraphReferenceInfo.NAME, GEO_OBJECT);
mdGeoObject.setStructValue(MdAttributeGraphReferenceInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "Geo Object");
mdGeoObject.apply();
// DefaultAttribute.CODE
MdAttributeCharacterDAO vertexCodeMdAttr = MdAttributeCharacterDAO.newInstance();
vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.CODE.getName());
vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultLocalizedName());
vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultDescription());
vertexCodeMdAttr.setValue(MdAttributeCharacterInfo.SIZE, MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdVertex.getOid());
vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
vertexCodeMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.UNIQUE_INDEX.getOid());
vertexCodeMdAttr.apply();
businessType.setMdVertexId(mdVertex.getOid());
// Assign permissions
Roles role = Roles.findRoleByName(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE);
RoleDAO roleDAO = (RoleDAO) BusinessFacade.getEntityDAO(role);
roleDAO.grantPermission(Operation.CREATE, mdVertex.getOid());
roleDAO.grantPermission(Operation.DELETE, mdVertex.getOid());
roleDAO.grantPermission(Operation.WRITE, mdVertex.getOid());
roleDAO.grantPermission(Operation.WRITE_ALL, mdVertex.getOid());
}
businessType.apply();
return businessType;
}
Aggregations