use of com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.
the class PatchHierarchicalRelationshipType method createHierarchicalRelationshipTypes.
public void createHierarchicalRelationshipTypes() {
MdBusiness univMdBusiness = MdBusiness.getMdBusiness(Universal.CLASS);
MdTermRelationshipQuery trq = new MdTermRelationshipQuery(new QueryFactory());
trq.WHERE(trq.getParentMdBusiness().EQ(univMdBusiness).AND(trq.getChildMdBusiness().EQ(univMdBusiness)));
try (OIterator<? extends MdTermRelationship> it = trq.getIterator()) {
it.getAll().stream().filter(mdTermRel -> {
if (!(mdTermRel.definesType().equals(IsARelationship.CLASS) || mdTermRel.getKey().equals(AllowedIn.CLASS) || mdTermRel.getKey().equals(LocatedIn.CLASS))) {
return (HierarchicalRelationshipType.getByMdTermRelationship(mdTermRel) == null);
}
return false;
}).forEach(mdTermRel -> {
System.out.println("Creating HierarchicalRelationshipType for the MdTermRelationship [" + mdTermRel.definesType() + "]");
String code = ServerHierarchyType.buildHierarchyKeyFromMdTermRelUniversal(mdTermRel.getKey());
String geoEntityKey = ServerHierarchyType.buildMdTermRelGeoEntityKey(code);
String mdEdgeKey = ServerHierarchyType.buildMdEdgeKey(code);
MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(mdEdgeKey);
String ownerActerOid = mdTermRel.getOwnerId();
String organizationCode = Organization.getRootOrganizationCode(ownerActerOid);
Organization organization = Organization.getByCode(organizationCode);
HierarchicalRelationshipType hierarchicalRelationship = new HierarchicalRelationshipType();
hierarchicalRelationship.setCode(code);
hierarchicalRelationship.setOrganization(organization);
hierarchicalRelationship.setMdTermRelationshipId(mdTermRel.getOid());
hierarchicalRelationship.setMdEdgeId(mdEdge.getOid());
try {
MdTermRelationship entityRelationship = MdTermRelationship.getByKey(geoEntityKey);
LocalizedValue displayLabel = AttributeTypeConverter.convert(entityRelationship.getDisplayLabel());
LocalizedValue description = AttributeTypeConverter.convert(entityRelationship.getDescription());
LocalizedValueConverter.populate(hierarchicalRelationship.getDisplayLabel(), displayLabel);
LocalizedValueConverter.populate(hierarchicalRelationship.getDescription(), description);
entityRelationship.delete();
} catch (DataNotFoundException | AttributeDoesNotExistException e) {
logger.debug("The entity geo relationship was not found defaulting to the mdTermRel displayLabel and description");
LocalizedValue displayLabel = AttributeTypeConverter.convert(mdTermRel.getDisplayLabel());
LocalizedValue description = AttributeTypeConverter.convert(mdTermRel.getDescription());
LocalizedValueConverter.populate(hierarchicalRelationship.getDisplayLabel(), displayLabel);
LocalizedValueConverter.populate(hierarchicalRelationship.getDescription(), description);
}
try {
BusinessDAOIF metadata = BusinessDAO.get("net.geoprism.registry.HierarchyMetadata", mdTermRel.getOid());
hierarchicalRelationship.setAbstractDescription(metadata.getValue("abstractDescription"));
hierarchicalRelationship.setAcknowledgement(metadata.getValue("acknowledgement"));
hierarchicalRelationship.setDisclaimer(metadata.getValue("disclaimer"));
hierarchicalRelationship.setContact(metadata.getValue("contact"));
hierarchicalRelationship.setPhoneNumber(metadata.getValue("phoneNumber"));
hierarchicalRelationship.setEmail(metadata.getValue("email"));
hierarchicalRelationship.setProgress(metadata.getValue("progress"));
hierarchicalRelationship.setAccessConstraints(metadata.getValue("accessConstraints"));
hierarchicalRelationship.setUseConstraints(metadata.getValue("useConstraints"));
} catch (DataNotFoundException | AttributeDoesNotExistException e) {
}
hierarchicalRelationship.apply();
});
}
}
use of com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.
the class ServerGeoObjectTypeConverter method build.
public ServerGeoObjectType build(Universal universal) {
MdBusiness mdBusiness = universal.getMdBusiness();
MdGeoVertexDAO mdVertex = GeoVertexType.getMdGeoVertex(universal.getUniversalId());
com.runwaysdk.system.gis.geo.GeometryType geoPrismgeometryType = universal.getGeometryType().get(0);
org.commongeoregistry.adapter.constants.GeometryType cgrGeometryType = GeometryTypeFactory.get(geoPrismgeometryType);
LocalizedValue label = convert(universal.getDisplayLabel());
LocalizedValue description = convert(universal.getDescription());
String ownerActerOid = universal.getOwnerOid();
String organizationCode = Organization.getRootOrganizationCode(ownerActerOid);
MdGeoVertexDAOIF superType = mdVertex.getSuperClass();
GeoObjectType geoObjType = new GeoObjectType(universal.getUniversalId(), cgrGeometryType, label, description, universal.getIsGeometryEditable(), organizationCode, ServiceFactory.getAdapter());
geoObjType.setIsAbstract(mdBusiness.getIsAbstract());
try {
GeoObjectTypeMetadata metadata = GeoObjectTypeMetadata.getByKey(universal.getKey());
geoObjType.setIsPrivate(metadata.getIsPrivate());
} catch (DataNotFoundException | AttributeDoesNotExistException e) {
geoObjType.setIsPrivate(false);
}
if (superType != null && !superType.definesType().equals(GeoVertex.CLASS)) {
String parentCode = superType.getTypeName();
geoObjType.setSuperTypeCode(parentCode);
}
geoObjType = this.convertAttributeTypes(universal, geoObjType, mdBusiness);
return new ServerGeoObjectType(geoObjType, universal, mdBusiness, mdVertex);
}
use of com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.
the class ServerGeoObjectTypeConverter method create.
@Transaction
public ServerGeoObjectType create(GeoObjectType geoObjectType) {
if (!MasterList.isValidName(geoObjectType.getCode())) {
throw new InvalidMasterListCodeException("The geo object type code has an invalid character");
}
if (geoObjectType.getCode().length() > 64) {
// Setting the typename on the MdBusiness creates this limitation.
CodeLengthException ex = new CodeLengthException();
ex.setLength(64);
throw ex;
}
ServiceFactory.getGeoObjectTypePermissionService().enforceCanCreate(geoObjectType.getOrganizationCode(), geoObjectType.getIsPrivate());
String superTypeCode = geoObjectType.getSuperTypeCode();
Boolean isAbstract = geoObjectType.getIsAbstract();
ServerGeoObjectType superType = null;
if (superTypeCode != null && superTypeCode.length() > 0) {
superType = ServerGeoObjectType.get(superTypeCode);
geoObjectType.setGeometryType(superType.getGeometryType());
}
if (isAbstract && superType != null) {
throw new ChainInheritanceException();
}
if (superType != null && !superType.getIsAbstract()) {
throw new GeoObjectTypeAssignmentException();
}
Universal universal = new Universal();
universal.setUniversalId(geoObjectType.getCode());
universal.setIsLeafType(false);
universal.setIsGeometryEditable(geoObjectType.isGeometryEditable());
// Set the owner of the universal to the id of the corresponding role of the
// responsible organization.
String organizationCode = geoObjectType.getOrganizationCode();
setOwner(universal, organizationCode);
populate(universal.getDisplayLabel(), geoObjectType.getLabel());
populate(universal.getDescription(), geoObjectType.getDescription());
com.runwaysdk.system.gis.geo.GeometryType geometryType = GeometryTypeFactory.get(geoObjectType.getGeometryType());
// Clear the default value
universal.clearGeometryType();
universal.addGeometryType(geometryType);
MdBusiness mdBusiness = new MdBusiness();
mdBusiness.setPackageName(RegistryConstants.UNIVERSAL_MDBUSINESS_PACKAGE);
// The CODE name becomes the class name
mdBusiness.setTypeName(universal.getUniversalId());
mdBusiness.setGenerateSource(false);
mdBusiness.setIsAbstract(isAbstract);
mdBusiness.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, universal.getDisplayLabel().getValue());
mdBusiness.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, universal.getDescription().getValue());
if (superType != null) {
mdBusiness.setSuperMdBusiness(superType.getMdBusiness());
} else {
mdBusiness.setPublish(false);
}
try {
// The DuplicateDataException on code was found to be thrown here.
// I've created a larger try/catch here just in case.
mdBusiness.apply();
// Add the default attributes.
if (superType == null) {
this.createDefaultAttributes(universal, mdBusiness);
}
universal.setMdBusiness(mdBusiness);
universal.apply();
GeoObjectTypeMetadata metadata = new GeoObjectTypeMetadata();
metadata.setIsPrivate(geoObjectType.getIsPrivate());
metadata.setUniversal(universal);
metadata.apply();
} catch (DuplicateDataException ex) {
DuplicateGeoObjectTypeException ex2 = new DuplicateGeoObjectTypeException();
ex2.setDuplicateValue(geoObjectType.getCode());
throw ex2;
}
// Create the MdGeoVertexClass
MdGeoVertexDAO mdVertex = GeoVertexType.create(universal.getUniversalId(), universal.getOwnerOid(), isAbstract, superType);
if (superType == null) {
this.createDefaultAttributes(universal, mdVertex);
assignSRAPermissions(mdVertex, mdBusiness);
assignAll_RA_Permissions(mdVertex, mdBusiness, organizationCode);
create_RM_GeoObjectTypeRole(mdVertex, organizationCode, geoObjectType.getCode());
assign_RM_GeoObjectTypeRole(mdVertex, mdBusiness, organizationCode, geoObjectType.getCode());
create_RC_GeoObjectTypeRole(mdVertex, organizationCode, geoObjectType.getCode());
assign_RC_GeoObjectTypeRole(mdVertex, mdBusiness, organizationCode, geoObjectType.getCode());
create_AC_GeoObjectTypeRole(mdVertex, organizationCode, geoObjectType.getCode());
assign_AC_GeoObjectTypeRole(mdVertex, mdBusiness, organizationCode, geoObjectType.getCode());
}
if (!isAbstract) {
// DefaultAttribute.CODE
MdAttributeCharacter businessCodeMdAttr = new MdAttributeCharacter();
businessCodeMdAttr.setAttributeName(DefaultAttribute.CODE.getName());
businessCodeMdAttr.getDisplayLabel().setValue(DefaultAttribute.CODE.getDefaultLocalizedName());
businessCodeMdAttr.getDescription().setValue(DefaultAttribute.CODE.getDefaultDescription());
businessCodeMdAttr.setDatabaseSize(MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
businessCodeMdAttr.setDefiningMdClass(mdBusiness);
businessCodeMdAttr.setRequired(true);
businessCodeMdAttr.addIndexType(MdAttributeIndices.UNIQUE_INDEX);
businessCodeMdAttr.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();
}
// Build the parent class term root if it does not exist.
TermConverter.buildIfNotExistdMdBusinessClassifier(mdBusiness);
ServerGeoObjectType serverGeoObjectType = this.build(universal);
return serverGeoObjectType;
}
use of com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.
the class ServerHierarchyTypeBuilder method newHierarchyToMdTermRelForUniversals.
/**
* It creates an {@link MdTermRelationship} to model the relationship between
* {@link Universal}s.
*
* Needs to occur in a transaction.
*
* @param hierarchyType
* @return
*/
public MdTermRelationship newHierarchyToMdTermRelForUniversals(HierarchyType hierarchyType) {
if (!MasterList.isValidName(hierarchyType.getCode())) {
throw new InvalidMasterListCodeException("The hierarchy type code has an invalid character");
}
MdBusiness mdBusUniversal = MdBusiness.getMdBusiness(Universal.CLASS);
MdTermRelationship mdTermRelationship = new MdTermRelationship();
// The Universal allpaths has a more restrictive limitation.
// try
// {
mdTermRelationship.setTypeName(hierarchyType.getCode() + RegistryConstants.UNIVERSAL_RELATIONSHIP_POST);
// }
// catch (AttributeLengthCharacterException e)
// {
// CodeLengthException ex = new CodeLengthException();
// ex.setLength(64 -
// RegistryConstants.UNIVERSAL_RELATIONSHIP_POST.length());
// throw ex;
// }
mdTermRelationship.setPackageName(GISConstants.GEO_PACKAGE);
populate(mdTermRelationship.getDisplayLabel(), hierarchyType.getLabel());
populate(mdTermRelationship.getDescription(), hierarchyType.getDescription());
mdTermRelationship.setIsAbstract(false);
mdTermRelationship.setGenerateSource(false);
mdTermRelationship.addCacheAlgorithm(RelationshipCache.CACHE_EVERYTHING);
mdTermRelationship.addAssociationType(AssociationType.Graph);
mdTermRelationship.setRemove(true);
// Create the relationship between different universals.
mdTermRelationship.setParentMdBusiness(mdBusUniversal);
mdTermRelationship.setParentCardinality("1");
mdTermRelationship.setChildMdBusiness(mdBusUniversal);
mdTermRelationship.setChildCardinality("*");
mdTermRelationship.setParentMethod("Parent");
mdTermRelationship.setChildMethod("Children");
// Set the owner of the universal to the id of the corresponding role of the
// responsible organization.
String organizationCode = hierarchyType.getOrganizationCode();
setOwner(mdTermRelationship, organizationCode);
return mdTermRelationship;
}
use of com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.
the class ServerHierarchyTypeBuilder method newHierarchyToMdTermRelForGeoEntities.
/**
* It creates an {@link MdTermRelationship} to model the relationship between
* {@link GeoEntity}s.
*
* Needs to occur in a transaction.
*
* @param hierarchyType
* @return
*/
public MdTermRelationship newHierarchyToMdTermRelForGeoEntities(HierarchyType hierarchyType) {
MdBusiness mdBusGeoEntity = MdBusiness.getMdBusiness(GeoEntity.CLASS);
MdTermRelationship mdTermRelationship = new MdTermRelationship();
mdTermRelationship.setTypeName(hierarchyType.getCode());
mdTermRelationship.setPackageName(GISConstants.GEO_PACKAGE);
populate(mdTermRelationship.getDisplayLabel(), hierarchyType.getLabel());
populate(mdTermRelationship.getDescription(), hierarchyType.getDescription());
mdTermRelationship.setIsAbstract(false);
mdTermRelationship.setGenerateSource(false);
mdTermRelationship.addCacheAlgorithm(RelationshipCache.CACHE_NOTHING);
mdTermRelationship.addAssociationType(AssociationType.Graph);
mdTermRelationship.setRemove(true);
// Create the relationship between different universals.
mdTermRelationship.setParentMdBusiness(mdBusGeoEntity);
mdTermRelationship.setParentCardinality("1");
mdTermRelationship.setChildMdBusiness(mdBusGeoEntity);
mdTermRelationship.setChildCardinality("*");
mdTermRelationship.setParentMethod("Parent");
mdTermRelationship.setChildMethod("Children");
// Set the owner of the universal to the id of the corresponding role of the
// responsible organization.
String organizationCode = hierarchyType.getOrganizationCode();
setOwner(mdTermRelationship, organizationCode);
return mdTermRelationship;
}
Aggregations