Example usage for javax.xml.registry Connection getRegistryService

List of usage examples for javax.xml.registry Connection getRegistryService

Introduction

In this page you can find the example usage for javax.xml.registry Connection getRegistryService.

Prototype

RegistryService getRegistryService() throws JAXRException;

Source Link

Document

Gets the RegistryService interface associated with the Connection.

Usage

From source file:it.cnr.icar.eric.client.ui.thin.security.SecurityUtil.java

/**
 *
 * @param principalName/*w ww. j a v  a  2s  . c  o  m*/
 * @throws JAXRException
 * @return
 */
public User findUserByPrincipalName(Connection connection, String principalName) throws JAXRException {
    User user = null;
    DeclarativeQueryManager dqm = connection.getRegistryService().getDeclarativeQueryManager();
    String queryString = "SELECT * " + "FROM user_ u, slot s " + "WHERE u.id = s.parent AND s.name_='"
            + CanonicalConstants.CANONICAL_PRINCIPAL_NAME_URI + "' AND value='" + principalName + "'";
    Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryString);
    BulkResponse br = dqm.executeQuery(query);
    Iterator<?> results = br.getCollection().iterator();
    while (results.hasNext()) {
        user = (User) results.next();
        break;
    }
    return user;
}

From source file:it.cnr.icar.eric.client.ui.swing.AdhocQuerySearchPanel.java

public void reloadModel() {
    final SwingWorker worker = new SwingWorker(this) {
        public Object doNonUILogic() {
            try {
                // This might take a while. Contructor should be running as SwingWorker
                JAXRClient client = RegistryBrowser.getInstance().getClient();
                Connection connection = client.getConnection();
                RegistryService service = connection.getRegistryService();
                dqm = (it.cnr.icar.eric.client.xml.registry.DeclarativeQueryManagerImpl) service
                        .getDeclarativeQueryManager();
                lcm = (it.cnr.icar.eric.client.xml.registry.LifeCycleManagerImpl) service
                        .getBusinessLifeCycleManager();
                processConfiguration();//from w  w w.  j  av  a 2  s  .c o m
                // model!!!
            } catch (JAXRException e) {
                throw new UndeclaredThrowableException(e);
            }
            return null;
        }

        @SuppressWarnings({ "unchecked", "rawtypes" })
        public void doUIUpdateLogic() {
            try {
                selectQueryCombo.setModel(new DefaultComboBoxModel(getQueryNames()));
                if (queries.size() > 0) {
                    setQuery(queries.get(0));
                }
            } catch (JAXRException e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    };
    worker.start();
}

From source file:it.cnr.icar.eric.client.ui.swing.BusinessQueryPanel.java

/**
 * Process a ConceptsTreeDialog.PROPERTY_SELECTED_CONCEPTS change event.
 *///from   w ww .ja  v  a2s .c om
private void processSelectedConceptsChange(PropertyChangeEvent ev) {
    try {
        Connection connection = RegistryBrowser.client.getConnection();
        RegistryService service = connection.getRegistryService();
        LifeCycleManager lcm = service.getBusinessLifeCycleManager();

        ArrayList<?> selectedConcepts = (ArrayList<?>) ev.getNewValue();
        ArrayList<Classification> classifications = new ArrayList<Classification>();

        Iterator<?> iter = selectedConcepts.iterator();

        while (iter.hasNext()) {
            Concept concept = (Concept) iter.next();
            Classification classification = lcm.createClassification(concept);
            classifications.add(classification);
        }

        ((ClassificationsListModel) (classificationsList.getModel())).setModels(classifications);
    } catch (JAXRException e) {
        RegistryBrowser.displayError(e);
    }
}

From source file:it.cnr.icar.eric.client.ui.swing.AdhocQuerySearchPanel.java

/**
 * Execute the query using parameters defined by the fields in QueryPanel.
 *//*from   w  ww.j  a va2s.c  om*/
BulkResponse executeQuery() {
    BulkResponse resp = null;

    try {
        Connection connection = RegistryBrowser.client.getConnection();
        @SuppressWarnings("unused")
        RegistryService service = connection.getRegistryService();

        HashMap<String, String> parameters = getParameters();
        QueryImpl query = (QueryImpl) dqm.createQuery(javax.xml.registry.Query.QUERY_TYPE_SQL);
        query.setFederated(isFederated());

        // make JAXR request
        resp = dqm.executeQuery(query, parameters);
    } catch (JAXRException e) {
        RegistryBrowser.displayError(e);
    }

    return resp;
}

From source file:it.cnr.icar.eric.client.ui.swing.BusinessQueryPanel.java

/**
 * Execute the query using parameters defined by the fields in QueryPanel.
 *///  w w w .j  ava  2 s  . c  o m
BulkResponse executeQuery() {
    BulkResponse resp = null;

    try {
        // create namePattern collection
        String nameStr = nameText.getText();
        String descStr = descText.getText();

        ArrayList<Object> classifications = ((ClassificationsListModel) (classificationsList.getModel()))
                .getModels();
        ArrayList<?> extIds = ((ExternalIdentifiersListModel) (extIdsList.getModel())).getModels();
        ArrayList<?> extLinks = ((ExternalLinksListModel) (linksList.getModel())).getModels();

        JAXRClient client = RegistryBrowser.getInstance().getClient();
        Connection connection = RegistryBrowser.client.getConnection();
        RegistryService service = connection.getRegistryService();
        @SuppressWarnings("unused")
        BusinessQueryManagerImpl bqm = (BusinessQueryManagerImpl) service.getBusinessQueryManager();
        DeclarativeQueryManagerImpl dqm = (DeclarativeQueryManagerImpl) service.getDeclarativeQueryManager();

        Object objectTypeObj = getObjectType();
        if (!(objectTypeObj instanceof Concept)) {
            throw new JAXRException("Search not supported for objectType: " + objectTypeObj.toString());
        }

        Concept objectType = (Concept) objectTypeObj;
        if (!(objectType.getPath()
                .startsWith("/" + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_ID_ObjectType))) {
            throw new JAXRException("Search not supported for objectType: " + objectType.getPath());
        }

        boolean isIntrinsic = isIntrinsicObjectType(objectType);
        boolean caseSensitive = caseSensitiveCheckBox.isSelected();

        // make declarative query
        String queryStr = "SELECT obj.* from ";

        if (isIntrinsic) {
            queryStr += (objectType.getValue() + " obj ");
        } else {
            //Following using RegistryObject as it could be an ExtrinsicObject
            //or an ExternalLink
            queryStr += "RegistryObject obj, ClassificationNode typeNode ";
        }

        //Add name to tables in join
        if ((nameStr != null) && (nameStr.length() != 0)) {
            queryStr += ", Name_ nm ";
        }

        //Add description to tables in join
        if ((descStr != null) && (descStr.length() != 0)) {
            queryStr += ", Description des ";
        }

        boolean addedPredicate = false;

        //Add objectType predicate
        if (!isIntrinsic) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += ("((obj.objectType = typeNode.id) AND " + "(typeNode.path LIKE '" + objectType.getPath()
                    + "' OR typeNode.path LIKE '" + objectType.getPath() + "/%'))");
        }

        //Add name predicate if needed
        if ((nameStr != null) && (nameStr.length() > 0)) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += ("((nm.parent = obj.id) AND ("
                    + BusinessQueryManagerImpl.caseSensitise("nm.value", caseSensitive) + " LIKE "
                    + BusinessQueryManagerImpl.caseSensitise("'" + nameStr + "'", caseSensitive) + ")) ");
        }

        //Add description predicate if needed
        if ((descStr != null) && (descStr.length() > 0)) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += ("((des.parent = obj.id) AND ("
                    + BusinessQueryManagerImpl.caseSensitise("des.value", caseSensitive) + " LIKE "
                    + BusinessQueryManagerImpl.caseSensitise("'" + descStr + "'", caseSensitive) + ")) ");
        }

        //Add nested query for Classifications if needed
        if (classifications.size() > 0) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += qu.getClassificationsPredicate(classifications, "obj.id", null);
        }

        //Add predicate for ExternalIdentifiers if needed
        if (extIds.size() > 0) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += qu.getExternalIdentifiersPredicate(extIds, "obj.id", null);
        }

        //Add nested query for ExternalLinks if needed
        if (extLinks.size() > 0) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += qu.getExternalLinksPredicate(extLinks, "obj.id", null);
        }

        QueryImpl query = (QueryImpl) dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);
        query.setFederated(isFederated());

        // make JAXR request
        resp = dqm.executeQuery(query);

        client.checkBulkResponse(resp);
    } catch (JAXRException e) {
        RegistryBrowser.displayError(e);
    }

    return resp;
}