Search in sources :

Example 41 with Transaction

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

the class GeoObjectEditorControllerNoOverTime method applyInTransaction.

@Transaction
private GeoObject applyInTransaction(String sessionId, String sPtn, String sGo, Boolean isNew, String masterListId) {
    final Date startDate = new Date();
    final Date endDate = ValueOverTime.INFINITY_END_DATE;
    GeoObject go;
    Map<String, String> roles = Session.getCurrentSession().getUserRoles();
    if (roles.keySet().contains(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE)) {
        Instant base = Instant.now();
        int sequence = 0;
        ChangeRequest request = new ChangeRequest();
        request.addApprovalStatus(AllGovernanceStatus.PENDING);
        request.apply();
        if (!isNew) {
            UpdateGeoObjectAction action = new UpdateGeoObjectAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setGeoObjectJson(sGo);
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        } else {
            CreateGeoObjectAction action = new CreateGeoObjectAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setGeoObjectJson(sGo);
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.apply();
            request.addAction(action).apply();
        }
        ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
        applyChangeRequest(sessionId, request, ptn, isNew, base, sequence, startDate, endDate);
    } else {
        if (!isNew) {
            go = RegistryService.getInstance().updateGeoObject(sessionId, sGo.toString(), startDate, endDate);
        } else {
            go = RegistryService.getInstance().createGeoObject(sessionId, sGo.toString(), startDate, endDate);
        }
        ParentTreeNode ptn = ParentTreeNode.fromJSON(sPtn.toString(), ServiceFactory.getAdapter());
        applyPtn(sessionId, ptn, startDate, endDate);
        // Update the master list record
        if (masterListId != null) {
            ServerGeoObjectService service = new ServerGeoObjectService();
            ServerGeoObjectIF geoObject = service.getGeoObject(go);
            if (!isNew) {
                ListTypeVersion.get(masterListId).updateRecord(geoObject);
            } else {
                ListTypeVersion.get(masterListId).publishRecord(geoObject);
            }
        }
        return go;
    }
    return null;
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) UpdateGeoObjectAction(net.geoprism.registry.action.geoobject.UpdateGeoObjectAction) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) Instant(java.time.Instant) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Date(java.util.Date) Endpoint(com.runwaysdk.mvc.Endpoint) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 42 with Transaction

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

the class ServerGeoObjectTypeConverter method createDefaultAttributes.

@Transaction
public void createDefaultAttributes(Universal universal, MdGraphClassDAOIF mdClass) {
    MdAttributeUUIDDAO uuidMdAttr = MdAttributeUUIDDAO.newInstance();
    uuidMdAttr.setValue(MdAttributeConcreteInfo.NAME, RegistryConstants.UUID);
    uuidMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, RegistryConstants.UUID_LABEL);
    uuidMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, RegistryConstants.UUID_LABEL);
    uuidMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdClass.getOid());
    uuidMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
    uuidMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.UNIQUE_INDEX.getOid());
    uuidMdAttr.apply();
    MdAttributeBooleanDAO existsMdAttr = MdAttributeBooleanDAO.newInstance();
    existsMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.EXISTS.getName());
    existsMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.EXISTS.getDefaultLocalizedName());
    existsMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.EXISTS.getDefaultDescription());
    existsMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdClass.getOid());
    existsMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.FALSE);
    existsMdAttr.setValue(MdAttributeConcreteInfo.DEFAULT_VALUE, MdAttributeBooleanInfo.FALSE);
    existsMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
    existsMdAttr.apply();
    MdAttributeBooleanDAO invalidMdAttr = MdAttributeBooleanDAO.newInstance();
    invalidMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.INVALID.getName());
    invalidMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.INVALID.getDefaultLocalizedName());
    invalidMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.INVALID.getDefaultDescription());
    invalidMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdClass.getOid());
    invalidMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
    invalidMdAttr.setValue(MdAttributeConcreteInfo.DEFAULT_VALUE, MdAttributeBooleanInfo.FALSE);
    invalidMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
    invalidMdAttr.apply();
    // DefaultAttribute.DISPLAY_LABEL
    MdAttributeLocalCharacterEmbeddedDAO labelMdAttr = MdAttributeLocalCharacterEmbeddedDAO.newInstance();
    labelMdAttr.setValue(MdAttributeLocalCharacterEmbeddedInfo.NAME, DefaultAttribute.DISPLAY_LABEL.getName());
    labelMdAttr.setStructValue(MdAttributeLocalCharacterEmbeddedInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.DISPLAY_LABEL.getDefaultLocalizedName());
    labelMdAttr.setStructValue(MdAttributeLocalCharacterEmbeddedInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.DISPLAY_LABEL.getDefaultDescription());
    labelMdAttr.setValue(MdAttributeLocalCharacterEmbeddedInfo.DEFINING_MD_CLASS, mdClass.getOid());
    labelMdAttr.setValue(MdAttributeLocalCharacterEmbeddedInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
    labelMdAttr.apply();
}
Also used : MdAttributeLocalCharacterEmbeddedDAO(com.runwaysdk.dataaccess.metadata.MdAttributeLocalCharacterEmbeddedDAO) MdAttributeBooleanDAO(com.runwaysdk.dataaccess.metadata.MdAttributeBooleanDAO) MdAttributeUUIDDAO(com.runwaysdk.dataaccess.metadata.MdAttributeUUIDDAO) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 43 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction 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 44 with Transaction

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

the class TermConverter method createClassifierFromTerm.

@Transaction
public static Classifier createClassifierFromTerm(String parentTermCode, Term term) {
    String parentClassifierKey = buildClassifierKeyFromTermCode(parentTermCode);
    Classifier parent = Classifier.getByKey(parentClassifierKey);
    enforceTermPermissions(parent, CGRPermissionAction.CREATE);
    Classifier classifier = new Classifier();
    classifier.setClassifierId(term.getCode());
    classifier.setClassifierPackage(parent.getKey());
    // This will set the value of the display label to the locale of the user
    // performing the action.
    LocalizedValueConverter.populate(classifier.getDisplayLabel(), term.getLabel());
    classifier.apply();
    classifier.addLink(parent, ClassifierIsARelationship.CLASS);
    return classifier;
}
Also used : Classifier(net.geoprism.ontology.Classifier) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 45 with Transaction

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

the class FhirResourceImporter method recordExportError.

@Transaction
private void recordExportError(Exception ex, ExportHistory history, Resource resource) {
    if (ex instanceof ProgrammingErrorException) {
        logger.error("Unknown error while processing the FHIR resource [" + resource.getId() + "]", ex);
    }
    if (this.history != null) {
        ExportError exportError = new ExportError();
        exportError.setCode(resource.getId());
        if (ex != null) {
            exportError.setErrorJson(JobHistory.exceptionToJson(ex).toString());
        }
        // exportError.setRowIndex(ee.rowIndex);
        exportError.setHistory(history);
        exportError.apply();
    }
}
Also used : ExportError(net.geoprism.registry.etl.export.ExportError) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

Transaction (com.runwaysdk.dataaccess.transaction.Transaction)131 QueryFactory (com.runwaysdk.query.QueryFactory)29 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)27 JsonObject (com.google.gson.JsonObject)17 Date (java.util.Date)15 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)15 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)14 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)13 LinkedList (java.util.LinkedList)11 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)11 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)10 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)10 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)10 List (java.util.List)10 ChangeRequest (net.geoprism.registry.action.ChangeRequest)10 VertexObject (com.runwaysdk.business.graph.VertexObject)8 IOException (java.io.IOException)8 GeoObjectImportConfiguration (net.geoprism.registry.io.GeoObjectImportConfiguration)8 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)8 JSONObject (org.json.JSONObject)8