use of com.runwaysdk.system.metadata.MdTermRelationship in project geoprism-registry by terraframe.
the class HierarchyMetadata method getHierarchyType.
public static ServerHierarchyType getHierarchyType(String key) {
HierarchyMetadata hierarchy = HierarchyMetadata.getByKey(key);
MdTermRelationship mdTermRelationship = hierarchy.getMdTermRelationship();
ServerHierarchyType hierarchyType = ServerHierarchyType.get(mdTermRelationship);
return hierarchyType;
}
use of com.runwaysdk.system.metadata.MdTermRelationship in project geoprism-registry by terraframe.
the class AddWritePermissions method reassignPermissions.
private void reassignPermissions(ServerHierarchyType hierarchyType) {
RoleDAO maintainer = RoleDAO.findRole(RegistryConstants.REGISTRY_MAINTAINER_ROLE).getBusinessDAO();
RoleDAO consumer = RoleDAO.findRole(RegistryConstants.API_CONSUMER_ROLE).getBusinessDAO();
RoleDAO contributor = RoleDAO.findRole(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE).getBusinessDAO();
InitializationStrategyIF strategy = new InitializationStrategyIF() {
@Override
public void preApply(MdBusinessDAO mdBusiness) {
mdBusiness.setValue(MdBusinessInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
}
@Override
public void postApply(MdBusinessDAO mdBusiness) {
RoleDAO adminRole = RoleDAO.findRole(DefaultConfiguration.ADMIN).getBusinessDAO();
adminRole.grantPermission(Operation.READ, mdBusiness.getOid());
adminRole.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
adminRole.grantPermission(Operation.WRITE, mdBusiness.getOid());
adminRole.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
adminRole.grantPermission(Operation.CREATE, mdBusiness.getOid());
adminRole.grantPermission(Operation.DELETE, mdBusiness.getOid());
maintainer.grantPermission(Operation.READ, mdBusiness.getOid());
maintainer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
maintainer.grantPermission(Operation.WRITE, mdBusiness.getOid());
maintainer.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
maintainer.grantPermission(Operation.CREATE, mdBusiness.getOid());
maintainer.grantPermission(Operation.DELETE, mdBusiness.getOid());
consumer.grantPermission(Operation.READ, mdBusiness.getOid());
consumer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
contributor.grantPermission(Operation.READ, mdBusiness.getOid());
contributor.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
}
};
String key = GISConstants.GEO_PACKAGE + "." + hierarchyType.getCode() + RegistryConstants.UNIVERSAL_RELATIONSHIP_POST;
if (hierarchyType.getCode().equals("LocatedIn")) {
key = GISConstants.GEO_PACKAGE + "." + hierarchyType.getCode();
}
MdTermRelationship mdTermRelUniversal = MdTermRelationship.getByKey(key);
this.grantWritePermissionsOnMdTermRel(mdTermRelUniversal);
this.grantWritePermissionsOnMdTermRel(maintainer, mdTermRelUniversal);
this.grantReadPermissionsOnMdTermRel(consumer, mdTermRelUniversal);
this.grantReadPermissionsOnMdTermRel(contributor, mdTermRelUniversal);
Universal.getStrategy().initialize(mdTermRelUniversal.definesType(), strategy);
MdTermRelationship mdTermRelGeoEntity = MdTermRelationship.getByKey(GISConstants.GEO_PACKAGE + "." + hierarchyType.getCode());
this.grantWritePermissionsOnMdTermRel(mdTermRelGeoEntity);
this.grantWritePermissionsOnMdTermRel(maintainer, mdTermRelGeoEntity);
this.grantReadPermissionsOnMdTermRel(consumer, mdTermRelGeoEntity);
this.grantReadPermissionsOnMdTermRel(contributor, mdTermRelGeoEntity);
MdEdgeDAO mdEdge = (MdEdgeDAO) MdEdgeDAO.getMdEdgeDAO(RegistryConstants.UNIVERSAL_GRAPH_PACKAGE + "." + hierarchyType.getCode());
this.grantWritePermissionsOnMdTermRel(mdEdge);
this.grantWritePermissionsOnMdTermRel(maintainer, mdEdge);
this.grantReadPermissionsOnMdTermRel(consumer, mdEdge);
this.grantReadPermissionsOnMdTermRel(contributor, mdEdge);
logger.info("Updated permissions for HierarchyType [" + hierarchyType.getCode() + "]. ");
}
use of com.runwaysdk.system.metadata.MdTermRelationship in project geoprism-registry by terraframe.
the class ServerHierarchyTypeBuilder method createHierarchyType.
@Transaction
public ServerHierarchyType createHierarchyType(HierarchyType hierarchyType) {
if (hierarchyType.getOrganizationCode() == null || hierarchyType.getOrganizationCode().equals("")) {
// TODO : A better exception
throw new AttributeValueException("Organization code cannot be null.", hierarchyType.getOrganizationCode());
}
Organization organization = Organization.getByCode(hierarchyType.getOrganizationCode());
String addons = new String(RegistryConstants.UNIVERSAL_RELATIONSHIP_POST + "AllPathsTable");
if (hierarchyType.getCode().length() > (64 - addons.length())) {
// Initializing the Universal allpaths strategy creates this limitation.
CodeLengthException ex = new CodeLengthException();
ex.setLength(64 - addons.length());
throw ex;
}
RoleDAO maintainer = RoleDAO.findRole(RegistryConstants.REGISTRY_MAINTAINER_ROLE).getBusinessDAO();
RoleDAO consumer = RoleDAO.findRole(RegistryConstants.API_CONSUMER_ROLE).getBusinessDAO();
RoleDAO contributor = RoleDAO.findRole(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE).getBusinessDAO();
InitializationStrategyIF strategy = new InitializationStrategyIF() {
@Override
public void preApply(MdBusinessDAO mdBusiness) {
mdBusiness.setValue(MdBusinessInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
}
@Override
public void postApply(MdBusinessDAO mdBusiness) {
RoleDAO adminRole = RoleDAO.findRole(DefaultConfiguration.ADMIN).getBusinessDAO();
adminRole.grantPermission(Operation.READ, mdBusiness.getOid());
adminRole.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
adminRole.grantPermission(Operation.WRITE, mdBusiness.getOid());
adminRole.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
adminRole.grantPermission(Operation.CREATE, mdBusiness.getOid());
adminRole.grantPermission(Operation.DELETE, mdBusiness.getOid());
maintainer.grantPermission(Operation.READ, mdBusiness.getOid());
maintainer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
maintainer.grantPermission(Operation.WRITE, mdBusiness.getOid());
maintainer.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
maintainer.grantPermission(Operation.CREATE, mdBusiness.getOid());
maintainer.grantPermission(Operation.DELETE, mdBusiness.getOid());
consumer.grantPermission(Operation.READ, mdBusiness.getOid());
consumer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
contributor.grantPermission(Operation.READ, mdBusiness.getOid());
contributor.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
}
};
try {
MdTermRelationship mdTermRelUniversal = this.newHierarchyToMdTermRelForUniversals(hierarchyType);
mdTermRelUniversal.apply();
this.grantWritePermissionsOnMdTermRel(mdTermRelUniversal);
this.grantWritePermissionsOnMdTermRel(maintainer, mdTermRelUniversal);
this.grantReadPermissionsOnMdTermRel(consumer, mdTermRelUniversal);
this.grantReadPermissionsOnMdTermRel(contributor, mdTermRelUniversal);
Universal.getStrategy().initialize(mdTermRelUniversal.definesType(), strategy);
MdEdge mdEdge = this.createMdEdge(hierarchyType);
this.grantWritePermissionsOnMdTermRel(mdEdge);
this.grantWritePermissionsOnMdTermRel(maintainer, mdEdge);
this.grantReadPermissionsOnMdTermRel(consumer, mdEdge);
this.grantReadPermissionsOnMdTermRel(contributor, mdEdge);
HierarchicalRelationshipType hierarchicalRelationship = new HierarchicalRelationshipType();
hierarchicalRelationship.setCode(hierarchyType.getCode());
hierarchicalRelationship.setOrganization(organization);
populate(hierarchicalRelationship.getDisplayLabel(), hierarchyType.getLabel());
populate(hierarchicalRelationship.getDescription(), hierarchyType.getDescription());
hierarchicalRelationship.setMdTermRelationship(mdTermRelUniversal);
hierarchicalRelationship.setMdEdge(mdEdge);
hierarchicalRelationship.setAbstractDescription(hierarchyType.getAbstractDescription());
hierarchicalRelationship.setAcknowledgement(hierarchyType.getAcknowledgement());
hierarchicalRelationship.setDisclaimer(hierarchyType.getDisclaimer());
hierarchicalRelationship.setContact(hierarchyType.getContact());
hierarchicalRelationship.setPhoneNumber(hierarchyType.getPhoneNumber());
hierarchicalRelationship.setEmail(hierarchyType.getEmail());
hierarchicalRelationship.setProgress(hierarchyType.getProgress());
hierarchicalRelationship.setAccessConstraints(hierarchyType.getAccessConstraints());
hierarchicalRelationship.setUseConstraints(hierarchyType.getUseConstraints());
hierarchicalRelationship.apply();
return this.get(hierarchicalRelationship);
} catch (DuplicateDataException ex) {
DuplicateHierarchyTypeException ex2 = new DuplicateHierarchyTypeException();
ex2.setDuplicateValue(hierarchyType.getCode());
throw ex2;
}
}
use of com.runwaysdk.system.metadata.MdTermRelationship in project geoprism-registry by terraframe.
the class HierarchicalRelationshipType method delete.
@Override
@Transaction
public void delete() {
MdTermRelationship mdTermRelationship = this.getMdTermRelationship();
MdEdge mdEdge = this.getMdEdge();
super.delete();
/*
* Delete all inherited hierarchies
*/
List<? extends InheritedHierarchyAnnotation> annotations = InheritedHierarchyAnnotation.getByRelationship(this);
for (InheritedHierarchyAnnotation annotation : annotations) {
annotation.delete();
}
Universal.getStrategy().shutdown(mdTermRelationship.definesType());
// AttributeHierarchy.deleteByRelationship(mdTermRelationship);
mdTermRelationship.delete();
mdEdge.delete();
}
use of com.runwaysdk.system.metadata.MdTermRelationship 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();
});
}
}
Aggregations