Package org.apache.stanbol.cmsadapter.servicesapi.repository

Examples of org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccess


                                   String password,
                                   String connectionType) throws RepositoryAccessException {

        ConnectionInfo connectionInfo = formConnectionInfo(repositoryURL, workspaceIdentifier, username,
            password, connectionType);
        RepositoryAccess repositoryAccess = repositoryAccessManager.getRepositoryAccessor(connectionInfo);

        if (repositoryAccess == null) {
            log.warn(String
                    .format(
                        "There is no suitable RepositoryAccess instance in the environment. \n Repository URL: %s\n Workspace identifier: %s\n Username: %s\n Password: %s\n Connection type: %s",
                        repositoryURL, workspaceIdentifier, username, password, connectionType));
            throw new RepositoryAccessException(
                    "There is no suitable RepositoryAccess instance in the environment. Please refer to logs");
        }
        Object session = repositoryAccess.getSession(connectionInfo);
        return cacheSessionContext(new SessionContext(session, connectionInfo));
    }
View Full Code Here


     */
    public Object getSession(String sessionKey) throws RepositoryAccessException {
        SessionContext sessionContext = sessions.get(sessionKey);
        if (sessionContext != null) {
            Object session = sessionContext.getSession();
            RepositoryAccess repositoryAccess = repositoryAccessManager.getRepositoryAccess(session);
            if (repositoryAccess != null) {
                boolean validSession = repositoryAccess.isSessionValid(session);
                if (validSession) {
                    return session;
                } else {
                    ConnectionInfo connectionInfo = sessionContext.getConnectionInfo();
                    session = repositoryAccess.getSession(connectionInfo);
                    log.info(String
                            .format(
                                "Session was invalid for the connection info. \n Repository URL: %s\n Workspace identifier: %s\n Username: %s\n Password: %s\n Connection type: %s",
                                connectionInfo.getRepositoryURL(), connectionInfo.getWorkspaceName(),
                                connectionInfo.getUsername(), connectionInfo.getPassword(),
View Full Code Here

        synchronized (accessors) {
            rai = accessors.iterator();
        }

        while (rai.hasNext()) {
            RepositoryAccess ra = rai.next();
            if (ra.canRetrieve(connectionInfo)) {
                return ra;
            }
        }

        logger.warn("No suitable repository access implementation for connection type {} ",
View Full Code Here

        synchronized (accessors) {
            rai = accessors.iterator();
        }

        while (rai.hasNext()) {
            RepositoryAccess ra = rai.next();
            if (ra.canRetrieve(session)) {
                return ra;
            }
        }

        if (session instanceof List<?>) {
View Full Code Here

        } else if (adapterMode.equals(AdapterMode.TOLERATED_OFFLINE)) {
            try {
                accessor = accessManager.getRepositoryAccessor(connectionInfo);
                this.session = accessor.getSession(connectionInfo);
                RepositoryAccess offlineAccess = accessManager.getRepositoryAccess(offlineObjects);
                this.adapter = new DObjectFactoryImp(accessor, offlineAccess, session, adapterMode);

            } catch (RepositoryAccessException e) {
                accessor = accessManager.getRepositoryAccess(offlineObjects);
                this.adapter = new DObjectFactoryImp(accessor, session, AdapterMode.STRICT_OFFLINE);
View Full Code Here

        if (engine.getBridgeDefinitions() != null) {
            DObjectAdapter adapter = engine.getDObjectAdapter();
            List<SubsumptionBridge> subsumptionBridges = MappingModelParser.getSubsumptionBridges(engine
                    .getBridgeDefinitions());
            Object session = engine.getSession();
            RepositoryAccess accessor = engine.getRepositoryAccess();
            boolean emptyList = (cmsObjects == null || cmsObjects.size() == 0);

            for (SubsumptionBridge sb : subsumptionBridges) {
                if (emptyList) {
                    try {
                        List<CMSObject> retrievedObjects = accessor.getNodeByPath(sb.getSubjectQuery(),
                            session);
                        cmsObjects = new ArrayList<DObject>();
                        for (CMSObject o : retrievedObjects) {
                            cmsObjects.add(adapter.wrapAsDObject(o));
                        }
View Full Code Here

        if (engine.getBridgeDefinitions() != null) {
            BridgeDefinitions bridgeDefinitions = engine.getBridgeDefinitions();
            DObjectAdapter adapter = engine.getDObjectAdapter();

            List<InstanceBridge> instanceBridges = MappingModelParser.getInstanceBridges(bridgeDefinitions);
            RepositoryAccess accessor = engine.getRepositoryAccess();
            Object session = engine.getSession();
            boolean emptyList = (cmsObjects == null || cmsObjects.size() == 0);

            for (InstanceBridge ib : instanceBridges) {
                // cms objects will be null in the case of initial bridge execution or update of bridge
                // definitions
                if (emptyList) {
                    try {
                        List<CMSObject> retrievedObjects = accessor.getNodeByPath(ib.getQuery(), session);
                        cmsObjects = new ArrayList<DObject>();
                        for (CMSObject o : retrievedObjects) {
                            cmsObjects.add(adapter.wrapAsDObject(o));
                        }
                    } catch (RepositoryAccessException e) {
View Full Code Here

        List<CMSObject> referencedNodes = resolveReferenceNodes(prop, engine);
        processPropertyAnnotation(annotation, subjectClass, referencedNodes, engine);
    }

    public List<CMSObject> resolveReferenceNodes(DProperty prop, MappingEngine engine) throws RepositoryAccessException {
        RepositoryAccess accessor = engine.getRepositoryAccess();
        Object session = engine.getSession();

        // TODO consider other property types
        List<CMSObject> referencedNodes = new ArrayList<CMSObject>();
        PropType type = prop.getDefinition().getPropertyType();
        if (type.equals(PropType.REFERENCE)) {
            // Resolve references
            // TODO need a better value representation than string
            // For example reference types may be resolved an put as an
            // objecttype
            for (String value : prop.getValue()) {
                try {
                    referencedNodes.addAll(accessor.getNodeById(value, session));
                } catch (RepositoryAccessException e) {
                    logger.warn("Error resolving reference value {}", value, e);
                }
            }

        } else if (type.equals(PropType.NAME)) {
            for (String name : prop.getValue()) {
                try {
                    referencedNodes.addAll(accessor.getNodeByName(name, session));
                } catch (Exception e) {
                    logger.warn("Error at getting name nodes.", e);
                }
            }

        } else if (type.equals(PropType.PATH)) {
            for (String value : prop.getValue()) {
                try {
                    referencedNodes.addAll(accessor.getNodeByPath(value, session));
                } catch (RepositoryAccessException e) {
                    logger.warn("Error at getting node by path ", e);
                }
            }
        }
View Full Code Here

                                       AnnotationType annotation,
                                       DProperty property,
                                       DPropertyDefinition propDef,
                                       MappingEngine engine) {

        RepositoryAccess accessor = engine.getRepositoryAccess();
        Object session = engine.getSession();
        OntologyResourceHelper orh = engine.getOntologyResourceHelper();

        // get referenced values
        List<CMSObject> referencedObjects = new ArrayList<CMSObject>();
        CMSObject parentObject = null;
        PropType type = propDef.getPropertyType();
        if (type == PropType.REFERENCE) {
            for (String referencedObject : property.getValue()) {
                try {
                    parentObject = accessor.getFirstNodeById(referencedObject, session);
                    if (parentObject != null) {
                        referencedObjects.add(parentObject);
                    }
                } catch (RepositoryAccessException e) {
                    logger.warn("Error while getting referenced value {} ", referencedObject, e);
                }
            }

        } else if (type == PropType.NAME) {
            for (String referencedName : property.getValue()) {
                List<CMSObject> names;
                try {
                    names = accessor.getNodeByName(referencedName, session);
                    referencedObjects.addAll(names);
                } catch (RepositoryAccessException e) {
                    logger.warn("Error while getting referenced value {} ", referencedName, e);
                }
            }
        } else if (type == PropType.PATH) {
            for (String referencedPath : property.getValue()) {
                try {
                    parentObject = accessor.getFirstNodeByPath(referencedPath, session);
                    if (parentObject != null) {
                        referencedObjects.add(parentObject);
                    }
                } catch (RepositoryAccessException e) {
                    logger.warn("Error while getting referenced value {} ", referencedPath, e);
View Full Code Here

    private void createDecoratedObjects(List<DObject> cmsObjects, MappingEngine engine) {
        // if there is bridge definitions try to fetch concept bridges
        if (engine.getBridgeDefinitions() != null) {
            List<ConceptBridge> conceptBridges = MappingModelParser.getConceptBridges(engine
                    .getBridgeDefinitions());
            RepositoryAccess accessor = engine.getRepositoryAccess();
            Object session = engine.getSession();
            DObjectAdapter adapter = engine.getDObjectAdapter();
            boolean emptyList = (cmsObjects == null || cmsObjects.size() == 0);

            for (ConceptBridge cb : conceptBridges) {
                // cms objects will be null in the case of initial bridge execution or update of bridge
                // definitions i.e when a BridgeDefinitionsResource service is called
                if (emptyList) {
                    try {
                        List<CMSObject> retrievedObjects = accessor.getNodeByPath(cb.getQuery(), session);
                        cmsObjects = new ArrayList<DObject>();
                        for (CMSObject o : retrievedObjects) {
                            cmsObjects.add(adapter.wrapAsDObject(o));
                        }
                    } catch (RepositoryAccessException e) {
View Full Code Here

TOP

Related Classes of org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.