Search in sources :

Example 1 with ServerHierarchyTypeBuilder

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();
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) RegistryAdapter(org.commongeoregistry.adapter.RegistryAdapter) Authenticate(com.runwaysdk.business.rbac.Authenticate)

Example 2 with ServerHierarchyTypeBuilder

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;
    }
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) MdEdgeDAO(com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) MdAttributeDateTimeDAO(com.runwaysdk.dataaccess.metadata.MdAttributeDateTimeDAO) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with ServerHierarchyTypeBuilder

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;
                }
            }
        }
    }
}
Also used : InheritedHierarchyAnnotationQuery(net.geoprism.registry.InheritedHierarchyAnnotationQuery) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) QueryFactory(com.runwaysdk.query.QueryFactory) Set(java.util.Set) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 4 with ServerHierarchyTypeBuilder

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
    }
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) QueryFactory(com.runwaysdk.query.QueryFactory) Universal(com.runwaysdk.system.gis.geo.Universal) ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) Organization(net.geoprism.registry.Organization) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) OrganizationQuery(net.geoprism.registry.OrganizationQuery) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) UniversalQuery(com.runwaysdk.system.gis.geo.UniversalQuery)

Example 5 with ServerHierarchyTypeBuilder

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);
}
Also used : HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) Request(com.runwaysdk.session.Request)

Aggregations

ServerHierarchyTypeBuilder (net.geoprism.registry.conversion.ServerHierarchyTypeBuilder)7 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)5 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)3 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)3 RoleDAO (com.runwaysdk.business.rbac.RoleDAO)2 DuplicateDataException (com.runwaysdk.dataaccess.DuplicateDataException)2 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)2 MdAttributeDateTimeDAO (com.runwaysdk.dataaccess.metadata.MdAttributeDateTimeDAO)2 MdEdgeDAO (com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO)2 QueryFactory (com.runwaysdk.query.QueryFactory)2 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)2 Authenticate (com.runwaysdk.business.rbac.Authenticate)1 Request (com.runwaysdk.session.Request)1 Universal (com.runwaysdk.system.gis.geo.Universal)1 UniversalQuery (com.runwaysdk.system.gis.geo.UniversalQuery)1 Set (java.util.Set)1 HierarchicalRelationshipType (net.geoprism.registry.HierarchicalRelationshipType)1 InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)1 InheritedHierarchyAnnotationQuery (net.geoprism.registry.InheritedHierarchyAnnotationQuery)1 Organization (net.geoprism.registry.Organization)1