use of net.geoprism.registry.HierarchicalRelationshipType in project geoprism-registry by terraframe.
the class PatchInheritedAnnotation method transaction.
@Transaction
private void transaction() {
InheritedHierarchyAnnotationQuery query = new InheritedHierarchyAnnotationQuery(new QueryFactory());
query.ORDER_BY(query.getForHierarchicalRelationshipType(), SortOrder.DESC);
query.ORDER_BY(query.getCreateDate(), SortOrder.DESC);
try (OIterator<? extends InheritedHierarchyAnnotation> iterator = query.getIterator()) {
InheritedHierarchyAnnotation prev = null;
while (iterator.hasNext()) {
InheritedHierarchyAnnotation annotation = iterator.next();
if (prev != null && prev.getForHierarchicalRelationshipTypeOid().equals(annotation.getForHierarchicalRelationshipTypeOid())) {
annotation.delete();
} else if (annotation.getForHierarchicalRelationshipTypeOid() == null || annotation.getForHierarchicalRelationshipTypeOid().length() == 0) {
annotation.delete();
} else {
// Determine if the inherited hierarchy and for hierarchy have the
// same root
ServerGeoObjectType inheritedNode = ServerGeoObjectType.get(annotation.getUniversal());
HierarchicalRelationshipType inheritedHierarchicalType = annotation.getInheritedHierarchicalRelationshipType();
ServerHierarchyType inheritedHierarchy = new ServerHierarchyTypeBuilder().get(inheritedHierarchicalType);
Set<String> rootCodes = inheritedHierarchy.getRootGeoObjectTypes().stream().map(type -> type.getGeoObjectType().getCode()).collect(Collectors.toSet());
if (rootCodes.contains(inheritedNode.getCode())) {
annotation.delete();
} else {
prev = annotation;
}
}
}
}
}
use of net.geoprism.registry.HierarchicalRelationshipType 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 net.geoprism.registry.HierarchicalRelationshipType in project geoprism-registry by terraframe.
the class PatchHierarchicalRelationshipType method migrateInheritedHierarchyAnnotation.
public void migrateInheritedHierarchyAnnotation() {
InheritedHierarchyAnnotationQuery query = new InheritedHierarchyAnnotationQuery(new QueryFactory());
try (OIterator<? extends InheritedHierarchyAnnotation> it = query.getIterator()) {
it.getAll().forEach(annotation -> {
HierarchicalRelationshipType forHierarchicalRelationshipType = HierarchicalRelationshipType.getByMdTermRelationship(annotation.getForHierarchy());
HierarchicalRelationshipType inheritedHierarchicalRelationshipType = HierarchicalRelationshipType.getByMdTermRelationship(annotation.getInheritedHierarchy());
annotation.appLock();
annotation.setForHierarchicalRelationshipType(forHierarchicalRelationshipType);
annotation.setInheritedHierarchicalRelationshipType(inheritedHierarchicalRelationshipType);
annotation.apply();
});
}
}
use of net.geoprism.registry.HierarchicalRelationshipType 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 net.geoprism.registry.HierarchicalRelationshipType in project geoprism-registry by terraframe.
the class ServerGeoObjectType method setInheritedHierarchy.
@Transaction
public InheritedHierarchyAnnotation setInheritedHierarchy(ServerHierarchyType forHierarchy, ServerHierarchyType inheritedHierarchy) {
// Hierarchy"
if (!this.isRoot(forHierarchy) || this.getIsAbstract()) {
throw new HierarchyRootException();
}
HierarchicalRelationshipType fhrt = forHierarchy.getHierarchicalRelationshipType();
HierarchicalRelationshipType ihrt = inheritedHierarchy.getHierarchicalRelationshipType();
if (InheritedHierarchyAnnotation.getByForHierarchical(fhrt) != null) {
throw new UnsupportedOperationException("A hierarchy cannot inherit from more than one other hierarchy");
}
if (this.isRoot(inheritedHierarchy)) {
throw new UnsupportedOperationException("A root node in a hierarchy cannot be inherited");
}
InheritedHierarchyAnnotation annotation = new InheritedHierarchyAnnotation();
annotation.setUniversal(this.universal);
annotation.setInheritedHierarchicalRelationshipType(ihrt);
annotation.setForHierarchicalRelationshipType(fhrt);
annotation.apply();
return annotation;
}
Aggregations