use of com.runwaysdk.dataaccess.transaction.TransactionState in project geoprism-registry by terraframe.
the class ServerGeoObjectType method getFromCache.
@SuppressWarnings("unchecked")
private static ServerGeoObjectType getFromCache(String code) {
TransactionState state = TransactionState.getCurrentTransactionState();
if (state != null) {
Object transactionCache = state.getTransactionObject("transaction-state");
if (transactionCache != null) {
Map<String, ServerElement> cache = (Map<String, ServerElement>) transactionCache;
ServerElement element = cache.get(code);
if (element != null && element instanceof ServerGeoObjectType) {
return (ServerGeoObjectType) element;
}
}
}
return ServiceFactory.getMetadataCache().getGeoObjectType(code).get();
}
use of com.runwaysdk.dataaccess.transaction.TransactionState in project geoprism-registry by terraframe.
the class ServerGeoObjectType method get.
@SuppressWarnings("unchecked")
public static ServerGeoObjectType get(String code, boolean nullIfNotFound) {
if (code == null || code.equals(Universal.ROOT)) {
return RootGeoObjectType.INSTANCE;
}
TransactionState state = TransactionState.getCurrentTransactionState();
if (state != null) {
Object transactionCache = state.getTransactionObject("transaction-state");
if (transactionCache != null) {
Map<String, ServerElement> cache = (Map<String, ServerElement>) transactionCache;
ServerElement element = cache.get(code);
if (element != null && element instanceof ServerGeoObjectType) {
return (ServerGeoObjectType) element;
}
}
}
Optional<ServerGeoObjectType> geoObjectType = ServiceFactory.getMetadataCache().getGeoObjectType(code);
if (geoObjectType.isPresent()) {
return geoObjectType.get();
} else if (!nullIfNotFound) {
net.geoprism.registry.DataNotFoundException ex = new net.geoprism.registry.DataNotFoundException();
ex.setTypeLabel(GeoObjectTypeMetadata.sGetClassDisplayLabel());
ex.setDataIdentifier(code);
ex.setAttributeLabel(GeoObjectTypeMetadata.getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
throw ex;
}
return null;
}
use of com.runwaysdk.dataaccess.transaction.TransactionState in project geoprism-registry by terraframe.
the class XMLImporter method importXMLDefinitions.
@Transaction
public List<ServerElement> importXMLDefinitions(Organization organization, InputStream istream) {
TransactionState state = TransactionState.getCurrentTransactionState();
state.putTransactionObject("transaction-state", this.cache);
LinkedList<ServerElement> list = new LinkedList<ServerElement>();
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = factory.newDocumentBuilder();
Document doc = dBuilder.parse(istream);
list.addAll(this.createTypes(organization, doc));
list.addAll(this.createHierarchies(organization, doc));
list.addAll(this.createDirectedAcyclicGraphTypes(doc));
list.addAll(this.createUndirectedGraphTypes(doc));
} catch (ParserConfigurationException | IOException | SAXException e) {
throw new ProgrammingErrorException(e);
}
return list;
}
Aggregations