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;
}
}
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;
}
}
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;
}
}
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();
}
}
}
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;
}
}
Aggregations