use of net.geoprism.registry.conversion.ServerHierarchyTypeBuilder in project geoprism-registry by terraframe.
the class GeoRegistryUtil method createHierarchyType.
@Authenticate
public static String createHierarchyType(String htJSON) {
RegistryAdapter adapter = ServiceFactory.getAdapter();
HierarchyType hierarchyType = HierarchyType.fromJSON(htJSON, adapter);
ServiceFactory.getHierarchyPermissionService().enforceCanCreate(hierarchyType.getOrganizationCode());
ServerHierarchyType sType = new ServerHierarchyTypeBuilder().createHierarchyType(hierarchyType);
// The transaction did not error out, so it is safe to put into the cache.
ServiceFactory.getMetadataCache().addHierarchyType(sType);
return hierarchyType.getCode();
}
use of net.geoprism.registry.conversion.ServerHierarchyTypeBuilder in project geoprism-registry by terraframe.
the class UndirectedGraphType method create.
@Transaction
public static UndirectedGraphType create(String code, LocalizedValue label, LocalizedValue description) {
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();
try {
MdVertexDAOIF mdBusGeoEntity = MdVertexDAO.getMdVertexDAO(GeoVertex.CLASS);
MdEdgeDAO mdEdgeDAO = MdEdgeDAO.newInstance();
mdEdgeDAO.setValue(MdEdgeInfo.PACKAGE, RegistryConstants.UNDIRECTED_GRAPH_PACKAGE);
mdEdgeDAO.setValue(MdEdgeInfo.NAME, code);
mdEdgeDAO.setValue(MdEdgeInfo.PARENT_MD_VERTEX, mdBusGeoEntity.getOid());
mdEdgeDAO.setValue(MdEdgeInfo.CHILD_MD_VERTEX, mdBusGeoEntity.getOid());
LocalizedValueConverter.populate(mdEdgeDAO, MdEdgeInfo.DISPLAY_LABEL, label);
LocalizedValueConverter.populate(mdEdgeDAO, MdEdgeInfo.DESCRIPTION, description);
mdEdgeDAO.setValue(MdEdgeInfo.ENABLE_CHANGE_OVER_TIME, MdAttributeBooleanInfo.FALSE);
mdEdgeDAO.apply();
MdAttributeDateTimeDAO startDate = MdAttributeDateTimeDAO.newInstance();
startDate.setValue(MdAttributeDateTimeInfo.NAME, GeoVertex.START_DATE);
startDate.setStructValue(MdAttributeDateTimeInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "Start Date");
startDate.setStructValue(MdAttributeDateTimeInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "Start Date");
startDate.setValue(MdAttributeDateTimeInfo.DEFINING_MD_CLASS, mdEdgeDAO.getOid());
startDate.apply();
MdAttributeDateTimeDAO endDate = MdAttributeDateTimeDAO.newInstance();
endDate.setValue(MdAttributeDateTimeInfo.NAME, GeoVertex.END_DATE);
endDate.setStructValue(MdAttributeDateTimeInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "End Date");
endDate.setStructValue(MdAttributeDateTimeInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "End Date");
endDate.setValue(MdAttributeDateTimeInfo.DEFINING_MD_CLASS, mdEdgeDAO.getOid());
endDate.apply();
ServerHierarchyTypeBuilder permissionBuilder = new ServerHierarchyTypeBuilder();
permissionBuilder.grantWritePermissionsOnMdTermRel(mdEdgeDAO);
permissionBuilder.grantWritePermissionsOnMdTermRel(maintainer, mdEdgeDAO);
permissionBuilder.grantReadPermissionsOnMdTermRel(consumer, mdEdgeDAO);
permissionBuilder.grantReadPermissionsOnMdTermRel(contributor, mdEdgeDAO);
UndirectedGraphType graphType = new UndirectedGraphType();
graphType.setCode(code);
graphType.setMdEdgeId(mdEdgeDAO.getOid());
LocalizedValueConverter.populate(graphType.getDisplayLabel(), label);
LocalizedValueConverter.populate(graphType.getDescription(), description);
graphType.apply();
return graphType;
} catch (DuplicateDataException ex) {
DuplicateHierarchyTypeException ex2 = new DuplicateHierarchyTypeException();
ex2.setDuplicateValue(code);
throw ex2;
}
}
use of net.geoprism.registry.conversion.ServerHierarchyTypeBuilder 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.conversion.ServerHierarchyTypeBuilder in project geoprism-registry by terraframe.
the class RegistryService method refreshMetadataCache.
public void refreshMetadataCache() {
ServiceFactory.getMetadataCache().rebuild();
QueryFactory qf = new QueryFactory();
UniversalQuery uq = new UniversalQuery(qf);
OIterator<? extends Universal> it = uq.getIterator();
try {
while (it.hasNext()) {
Universal uni = it.next();
if (uni.getKey().equals(Universal.ROOT_KEY)) {
continue;
}
ServerGeoObjectType type = new ServerGeoObjectTypeConverter().build(uni);
ServiceFactory.getMetadataCache().addGeoObjectType(type);
}
} finally {
it.close();
}
// We must build the hierarchy types which are inherited first
// Otherwise you will end up with a NPE when building the hierarchies
// which inherit the inherited hierarchy if it hasn't been built
HierarchicalRelationshipType.getInheritedTypes().forEach(relationship -> {
ServerHierarchyType ht = new ServerHierarchyTypeBuilder().get(relationship, false);
ServiceFactory.getMetadataCache().addHierarchyType(ht);
});
HierarchicalRelationshipType.getAll().forEach(relationship -> {
ServerHierarchyType ht = new ServerHierarchyTypeBuilder().get(relationship, false);
if (!ServiceFactory.getMetadataCache().getHierachyType(ht.getCode()).isPresent()) {
ServiceFactory.getMetadataCache().addHierarchyType(ht);
}
});
try {
// This is, unfortunately, a big hack. Some patch items need to occur
// before the organizaiton class is defined
MdClassDAO.getMdClassDAO(Organization.CLASS);
OrganizationQuery oQ = new OrganizationQuery(qf);
OIterator<? extends Organization> it3 = oQ.getIterator();
try {
while (it3.hasNext()) {
Organization organization = it3.next();
ServiceFactory.getMetadataCache().addOrganization(organization);
}
} finally {
it3.close();
}
} catch (com.runwaysdk.dataaccess.cache.DataNotFoundException e) {
// skip for now
}
}
use of net.geoprism.registry.conversion.ServerHierarchyTypeBuilder in project geoprism-registry by terraframe.
the class TestHierarchyTypeInfo method apply.
@Request
public void apply() {
if (this.getServerObject(true) != null) {
return;
}
HierarchyType dto = this.toDTO();
this.serverObj = new ServerHierarchyTypeBuilder().createHierarchyType(dto);
}
Aggregations