Search in sources :

Example 1 with DuplicateDataException

use of com.runwaysdk.dataaccess.DuplicateDataException 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 2 with DuplicateDataException

use of com.runwaysdk.dataaccess.DuplicateDataException 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;
    }
}
Also used : Organization(net.geoprism.registry.Organization) MdEdge(com.runwaysdk.system.metadata.MdEdge) DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) DuplicateHierarchyTypeException(net.geoprism.registry.DuplicateHierarchyTypeException) InitializationStrategyIF(com.runwaysdk.business.ontology.InitializationStrategyIF) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) AttributeValueException(com.runwaysdk.dataaccess.attributes.AttributeValueException) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship) CodeLengthException(net.geoprism.registry.CodeLengthException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with DuplicateDataException

use of com.runwaysdk.dataaccess.DuplicateDataException in project geoprism-registry by terraframe.

the class ServerGeoObjectService method apply.

@Transaction
public ServerGeoObjectIF apply(GeoObject object, Date startDate, Date endDate, boolean isNew, boolean isImport) {
    ServerGeoObjectType type = ServerGeoObjectType.get(object.getType());
    ServerGeoObjectStrategyIF strategy = this.getStrategy(type);
    if (isNew) {
        permissionService.enforceCanCreate(type.getOrganization().getCode(), type);
    } else {
        permissionService.enforceCanWrite(type.getOrganization().getCode(), type);
    }
    ServerGeoObjectIF geoObject = strategy.constructFromGeoObject(object, isNew);
    geoObject.setDate(startDate);
    if (!isNew) {
        geoObject.lock();
    }
    geoObject.populate(object, startDate, endDate);
    try {
        geoObject.apply(isImport);
        // Return the refreshed copy of the geoObject
        return this.build(type, geoObject.getRunwayId());
    } catch (DuplicateDataException e) {
        VertexServerGeoObject.handleDuplicateDataException(type, e);
        throw e;
    }
}
Also used : DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ServerGeoObjectStrategyIF(net.geoprism.registry.conversion.ServerGeoObjectStrategyIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 4 with DuplicateDataException

use of com.runwaysdk.dataaccess.DuplicateDataException in project geoprism-registry by terraframe.

the class BusinessObjectImporterTest method testImportValueExistingNewOnly.

@Test
@Request
public void testImportValueExistingNewOnly() throws InterruptedException {
    BusinessObject object = BusinessObject.newInstance(type);
    object.setCode(TEST_CODE);
    object.apply();
    try {
        String value = "Test Text";
        String rowAttribute = "Bad";
        HashMap<String, Object> row = new HashMap<String, Object>();
        row.put(rowAttribute, value);
        row.put(BusinessObject.CODE, TEST_CODE);
        BusinessObjectImportConfiguration configuration = new BusinessObjectImportConfiguration();
        configuration.setImportStrategy(ImportStrategy.NEW_ONLY);
        configuration.setType(type);
        configuration.setDate(FastTestDataset.DEFAULT_END_TIME_DATE);
        configuration.setCopyBlank(false);
        configuration.setFunction(attributeType.getName(), new BasicColumnFunction(rowAttribute));
        configuration.setFunction(BusinessObject.CODE, new BasicColumnFunction(BusinessObject.CODE));
        BusinessObjectImporter importer = new BusinessObjectImporter(configuration, new NullImportProgressListener());
        importer.importRow(new MapFeatureRow(row));
        Assert.assertTrue(configuration.hasExceptions());
        LinkedList<BusinessObjectRecordedErrorException> exceptions = configuration.getExceptions();
        Assert.assertEquals(1, exceptions.size());
        BusinessObjectRecordedErrorException exception = exceptions.get(0);
        Assert.assertTrue(exception.getError() instanceof DuplicateDataException);
    } finally {
        if (object != null) {
            object.delete();
        }
    }
}
Also used : HashMap(java.util.HashMap) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) BusinessObjectImportConfiguration(net.geoprism.registry.etl.upload.BusinessObjectImportConfiguration) BusinessObject(net.geoprism.registry.model.BusinessObject) BusinessObjectImporter(net.geoprism.registry.etl.upload.BusinessObjectImporter) DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) BusinessObjectRecordedErrorException(net.geoprism.registry.etl.upload.BusinessObjectRecordedErrorException) NullImportProgressListener(net.geoprism.registry.etl.NullImportProgressListener) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) BusinessObject(net.geoprism.registry.model.BusinessObject) MapFeatureRow(net.geoprism.registry.excel.MapFeatureRow) Test(org.junit.Test) Request(com.runwaysdk.session.Request)

Example 5 with DuplicateDataException

use of com.runwaysdk.dataaccess.DuplicateDataException in project geoprism-registry by terraframe.

the class DirectedAcyclicGraphType method create.

@Transaction
public static DirectedAcyclicGraphType 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.DAG_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);
        DirectedAcyclicGraphType graphType = new DirectedAcyclicGraphType();
        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)

Aggregations

DuplicateDataException (com.runwaysdk.dataaccess.DuplicateDataException)7 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)6 RoleDAO (com.runwaysdk.business.rbac.RoleDAO)3 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)3 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)2 MdAttributeDateTimeDAO (com.runwaysdk.dataaccess.metadata.MdAttributeDateTimeDAO)2 MdEdgeDAO (com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO)2 CodeLengthException (net.geoprism.registry.CodeLengthException)2 ServerGeoObjectStrategyIF (net.geoprism.registry.conversion.ServerGeoObjectStrategyIF)2 ServerHierarchyTypeBuilder (net.geoprism.registry.conversion.ServerHierarchyTypeBuilder)2 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)2 JsonObject (com.google.gson.JsonObject)1 InitializationStrategyIF (com.runwaysdk.business.ontology.InitializationStrategyIF)1 AttributeValueException (com.runwaysdk.dataaccess.attributes.AttributeValueException)1 MdAttributeCharacterDAO (com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO)1 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)1 MdGeoVertexDAO (com.runwaysdk.gis.dataaccess.metadata.graph.MdGeoVertexDAO)1 Request (com.runwaysdk.session.Request)1 Universal (com.runwaysdk.system.gis.geo.Universal)1 MdAttributeCharacter (com.runwaysdk.system.metadata.MdAttributeCharacter)1