Search in sources :

Example 6 with DuplicateDataException

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

the class ServerGeoObjectTypeConverter method create.

@Transaction
public ServerGeoObjectType create(GeoObjectType geoObjectType) {
    if (!MasterList.isValidName(geoObjectType.getCode())) {
        throw new InvalidMasterListCodeException("The geo object type code has an invalid character");
    }
    if (geoObjectType.getCode().length() > 64) {
        // Setting the typename on the MdBusiness creates this limitation.
        CodeLengthException ex = new CodeLengthException();
        ex.setLength(64);
        throw ex;
    }
    ServiceFactory.getGeoObjectTypePermissionService().enforceCanCreate(geoObjectType.getOrganizationCode(), geoObjectType.getIsPrivate());
    String superTypeCode = geoObjectType.getSuperTypeCode();
    Boolean isAbstract = geoObjectType.getIsAbstract();
    ServerGeoObjectType superType = null;
    if (superTypeCode != null && superTypeCode.length() > 0) {
        superType = ServerGeoObjectType.get(superTypeCode);
        geoObjectType.setGeometryType(superType.getGeometryType());
    }
    if (isAbstract && superType != null) {
        throw new ChainInheritanceException();
    }
    if (superType != null && !superType.getIsAbstract()) {
        throw new GeoObjectTypeAssignmentException();
    }
    Universal universal = new Universal();
    universal.setUniversalId(geoObjectType.getCode());
    universal.setIsLeafType(false);
    universal.setIsGeometryEditable(geoObjectType.isGeometryEditable());
    // Set the owner of the universal to the id of the corresponding role of the
    // responsible organization.
    String organizationCode = geoObjectType.getOrganizationCode();
    setOwner(universal, organizationCode);
    populate(universal.getDisplayLabel(), geoObjectType.getLabel());
    populate(universal.getDescription(), geoObjectType.getDescription());
    com.runwaysdk.system.gis.geo.GeometryType geometryType = GeometryTypeFactory.get(geoObjectType.getGeometryType());
    // Clear the default value
    universal.clearGeometryType();
    universal.addGeometryType(geometryType);
    MdBusiness mdBusiness = new MdBusiness();
    mdBusiness.setPackageName(RegistryConstants.UNIVERSAL_MDBUSINESS_PACKAGE);
    // The CODE name becomes the class name
    mdBusiness.setTypeName(universal.getUniversalId());
    mdBusiness.setGenerateSource(false);
    mdBusiness.setIsAbstract(isAbstract);
    mdBusiness.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, universal.getDisplayLabel().getValue());
    mdBusiness.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, universal.getDescription().getValue());
    if (superType != null) {
        mdBusiness.setSuperMdBusiness(superType.getMdBusiness());
    } else {
        mdBusiness.setPublish(false);
    }
    try {
        // The DuplicateDataException on code was found to be thrown here.
        // I've created a larger try/catch here just in case.
        mdBusiness.apply();
        // Add the default attributes.
        if (superType == null) {
            this.createDefaultAttributes(universal, mdBusiness);
        }
        universal.setMdBusiness(mdBusiness);
        universal.apply();
        GeoObjectTypeMetadata metadata = new GeoObjectTypeMetadata();
        metadata.setIsPrivate(geoObjectType.getIsPrivate());
        metadata.setUniversal(universal);
        metadata.apply();
    } catch (DuplicateDataException ex) {
        DuplicateGeoObjectTypeException ex2 = new DuplicateGeoObjectTypeException();
        ex2.setDuplicateValue(geoObjectType.getCode());
        throw ex2;
    }
    // Create the MdGeoVertexClass
    MdGeoVertexDAO mdVertex = GeoVertexType.create(universal.getUniversalId(), universal.getOwnerOid(), isAbstract, superType);
    if (superType == null) {
        this.createDefaultAttributes(universal, mdVertex);
        assignSRAPermissions(mdVertex, mdBusiness);
        assignAll_RA_Permissions(mdVertex, mdBusiness, organizationCode);
        create_RM_GeoObjectTypeRole(mdVertex, organizationCode, geoObjectType.getCode());
        assign_RM_GeoObjectTypeRole(mdVertex, mdBusiness, organizationCode, geoObjectType.getCode());
        create_RC_GeoObjectTypeRole(mdVertex, organizationCode, geoObjectType.getCode());
        assign_RC_GeoObjectTypeRole(mdVertex, mdBusiness, organizationCode, geoObjectType.getCode());
        create_AC_GeoObjectTypeRole(mdVertex, organizationCode, geoObjectType.getCode());
        assign_AC_GeoObjectTypeRole(mdVertex, mdBusiness, organizationCode, geoObjectType.getCode());
    }
    if (!isAbstract) {
        // DefaultAttribute.CODE
        MdAttributeCharacter businessCodeMdAttr = new MdAttributeCharacter();
        businessCodeMdAttr.setAttributeName(DefaultAttribute.CODE.getName());
        businessCodeMdAttr.getDisplayLabel().setValue(DefaultAttribute.CODE.getDefaultLocalizedName());
        businessCodeMdAttr.getDescription().setValue(DefaultAttribute.CODE.getDefaultDescription());
        businessCodeMdAttr.setDatabaseSize(MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
        businessCodeMdAttr.setDefiningMdClass(mdBusiness);
        businessCodeMdAttr.setRequired(true);
        businessCodeMdAttr.addIndexType(MdAttributeIndices.UNIQUE_INDEX);
        businessCodeMdAttr.apply();
        // DefaultAttribute.CODE
        MdAttributeCharacterDAO vertexCodeMdAttr = MdAttributeCharacterDAO.newInstance();
        vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.CODE.getName());
        vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultLocalizedName());
        vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultDescription());
        vertexCodeMdAttr.setValue(MdAttributeCharacterInfo.SIZE, MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
        vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdVertex.getOid());
        vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
        vertexCodeMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.UNIQUE_INDEX.getOid());
        vertexCodeMdAttr.apply();
    }
    // Build the parent class term root if it does not exist.
    TermConverter.buildIfNotExistdMdBusinessClassifier(mdBusiness);
    ServerGeoObjectType serverGeoObjectType = this.build(universal);
    return serverGeoObjectType;
}
Also used : GeoObjectTypeMetadata(net.geoprism.registry.model.GeoObjectTypeMetadata) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) Universal(com.runwaysdk.system.gis.geo.Universal) ChainInheritanceException(net.geoprism.registry.ChainInheritanceException) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) InvalidMasterListCodeException(net.geoprism.registry.InvalidMasterListCodeException) MdAttributeCharacterDAO(com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO) DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) DuplicateGeoObjectTypeException(net.geoprism.registry.DuplicateGeoObjectTypeException) MdGeoVertexDAO(com.runwaysdk.gis.dataaccess.metadata.graph.MdGeoVertexDAO) GeoObjectTypeAssignmentException(net.geoprism.registry.GeoObjectTypeAssignmentException) CodeLengthException(net.geoprism.registry.CodeLengthException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 7 with DuplicateDataException

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

the class ServerGeoObjectService method apply.

@Transaction
public ServerGeoObjectIF apply(GeoObjectOverTime goTime, boolean isNew, boolean isImport) {
    ServerGeoObjectType type = ServerGeoObjectType.get(goTime.getType());
    ServerGeoObjectStrategyIF strategy = this.getStrategy(type);
    if (isNew) {
        permissionService.enforceCanCreate(type.getOrganization().getCode(), type);
    } else {
        permissionService.enforceCanWrite(type.getOrganization().getCode(), type);
    }
    ServerGeoObjectIF goServer = strategy.constructFromGeoObjectOverTime(goTime, isNew);
    if (!isNew) {
        goServer.lock();
    }
    goServer.populate(goTime);
    try {
        goServer.apply(isImport);
        // Return the refreshed copy of the geoObject
        return this.build(type, goServer.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)

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