Search in sources :

Example 1 with TransactionState

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();
}
Also used : TransactionState(com.runwaysdk.dataaccess.transaction.TransactionState) JsonObject(com.google.gson.JsonObject) Map(java.util.Map)

Example 2 with TransactionState

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;
}
Also used : TransactionState(com.runwaysdk.dataaccess.transaction.TransactionState) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) JsonObject(com.google.gson.JsonObject) Map(java.util.Map)

Example 3 with TransactionState

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;
}
Also used : TransactionState(com.runwaysdk.dataaccess.transaction.TransactionState) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) ServerElement(net.geoprism.registry.model.ServerElement) LinkedList(java.util.LinkedList) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) SAXException(org.xml.sax.SAXException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

TransactionState (com.runwaysdk.dataaccess.transaction.TransactionState)3 JsonObject (com.google.gson.JsonObject)2 Map (java.util.Map)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)1 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ServerElement (net.geoprism.registry.model.ServerElement)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1