Example usage for javax.xml.registry BulkResponse getCollection

List of usage examples for javax.xml.registry BulkResponse getCollection

Introduction

In this page you can find the example usage for javax.xml.registry BulkResponse getCollection.

Prototype

Collection getCollection() throws JAXRException;

Source Link

Document

Get the Collection of objects returned as a response of a bulk operation.

Usage

From source file:it.cnr.icar.eric.client.ui.thin.jsf.ClassSchemeGraphBean.java

@SuppressWarnings({ "static-access", "unchecked" })
public Collection<?> getClassSchemes() {
    Collection<?> classSchemes = null;
    try {//from   w  w w  . j  ava  2s.  c om
        HashMap<String, String> queryParams = new HashMap<String, String>();
        queryParams.put(BindingUtility.getInstance().CANONICAL_SLOT_QUERY_ID,
                BindingUtility.getInstance().CANONICAL_QUERY_GetClassificationSchemesById);
        Query query = ((DeclarativeQueryManagerImpl) dqm).createQuery(Query.QUERY_TYPE_SQL);
        BulkResponse bResponse = ((DeclarativeQueryManagerImpl) dqm).executeQuery(query, queryParams);

        Collection<?> exceptions = bResponse.getExceptions();
        //TO DO: forward exceptions to an error JSP
        if (exceptions != null) {
            Iterator<?> iter = exceptions.iterator();
            Exception exception = null;
            @SuppressWarnings("unused")
            StringBuffer sb2 = new StringBuffer(WebUIResourceBundle.getInstance().getString("errorExecQuery"));
            while (iter.hasNext()) {
                exception = (Exception) iter.next();
            }
            log.error("\n" + exception.getMessage());
        }
        // Filter hidden schemes here.
        classSchemes = filterHiddenSchemes(bResponse.getCollection());
    } catch (Throwable t) {
        log.error(t.getMessage());
    }
    return classSchemes;
}

From source file:it.cnr.icar.eric.client.xml.registry.infomodel.RegistryObjectImpl.java

public Collection<?> getRegistryPackages() throws JAXRException {
    if (packages == null) {
        if (!isNew()) {
            HashMap<String, String> parameters = new HashMap<String, String>();
            parameters.put(CanonicalConstants.CANONICAL_SLOT_QUERY_ID,
                    CanonicalConstants.CANONICAL_QUERY_GetRegistryPackagesByMemberId);
            parameters.put("$memberId", getId());
            Query query = dqm.createQuery(Query.QUERY_TYPE_SQL);
            BulkResponse response = dqm.executeQuery(query, parameters);
            checkBulkResponseExceptions(response);
            @SuppressWarnings("unused")
            Collection<?> registryObjects = response.getCollection();
            packages = response.getCollection();
        }/*from  w w  w  . j  a va  2  s. co m*/

        if (packages == null) {
            packages = new ArrayList<Object>();
        }
    }

    return packages;
}

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

@SuppressWarnings("static-access")
protected void exportAction() {
    RegistryBrowser.setWaitCursor();/*ww w . j a v a 2  s.co m*/

    int[] selectedIndices = getSelectedRows();

    if (selectedIndices.length == 1) {
        RegistryObject ro = (RegistryObject) dataModel.getValueAt(selectedRow, -1);

        try {
            JAXRClient client = RegistryBrowser.getInstance().getClient();
            DeclarativeQueryManagerImpl dqm = client.getDeclarativeQueryManager();
            String queryId = CanonicalConstants.CANONICAL_QUERY_Export;
            Map<String, String> queryParams = new HashMap<String, String>();
            @SuppressWarnings("unused")
            String id = it.cnr.icar.eric.common.Utility.getInstance().createId();
            queryParams.put("$schemaComponentId", ro.getKey().getId());

            queryParams.put(BindingUtility.getInstance().CANONICAL_SLOT_QUERY_ID, queryId);
            Query query = dqm.createQuery(Query.QUERY_TYPE_SQL);

            //Add response option to ensure that RepositoryItem is returned
            String returnType = ReturnType.LEAF_CLASS_WITH_REPOSITORY_ITEM.value();
            queryParams.put(dqm.CANONICAL_SLOT_RESPONSEOPTION_RETURN_TYPE, returnType);

            BulkResponse bResponse = dqm.executeQuery(query, queryParams);
            Collection<?> registryObjects = bResponse.getCollection();
            RegistryBrowser.getInstance().exportToFile(registryObjects);

        } catch (ObjectNotFoundException e) {
            RegistryBrowser.displayError(resourceBundle.getString("message.info.exportFeatureNotConfigured"));
        } catch (Exception e) {
            RegistryBrowser.displayError(e);
        }

    } else {
        RegistryBrowser.displayError(resourceBundle.getString("message.error.cannotExportMultipleObjects"));
    }

    RegistryBrowser.setDefaultCursor();
}

From source file:it.cnr.icar.eric.client.xml.registry.infomodel.RegistryPackageTest.java

/**
 * Test that removeRegistryObject really does remove the
 * association between this RegistryPackage and the member
 * RegistryObject./*from  ww w. j  a v a 2  s  . c om*/
 *
 * @exception Exception if an error occurs
 */
@SuppressWarnings("static-access")
public void testRemoveRegistryObject() throws Exception {
    HashMap<String, String> saveObjectsSlots = new HashMap<String, String>();

    //The bulk loader MUST turn off versioning because it updates
    //objects in its operations which would incorrectly be created as
    //new objects if versioning is ON when the object is updated.
    saveObjectsSlots.put(bu.CANONICAL_SLOT_LCM_DONT_VERSION, "true");
    saveObjectsSlots.put(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT, "true");

    String testName = "testRemoveRegistryObject";

    String uuid1 = it.cnr.icar.eric.common.Utility.getInstance().createId();

    RegistryPackage pkg1 = getLCM().createRegistryPackage(uuid1);
    pkg1.setKey(getLCM().createKey(uuid1));
    pkg1.setDescription(getLCM().createInternationalString(testName));

    // -- Save the Object
    ArrayList<Object> objects = new ArrayList<Object>();
    objects.add(pkg1);
    BulkResponse resp = ((LifeCycleManagerImpl) getLCM()).saveObjects(objects, saveObjectsSlots);
    JAXRUtility.checkBulkResponse(resp);
    System.out.println("Created Registry Package with Id " + uuid1);

    String uuid2 = it.cnr.icar.eric.common.Utility.getInstance().createId();

    RegistryPackage pkg2 = getLCM().createRegistryPackage(uuid2);
    pkg2.setKey(getLCM().createKey(uuid2));
    pkg2.setDescription(getLCM().createInternationalString(testName));

    // -- Add pkg2 to Registry Package and save
    pkg1.addRegistryObject(pkg2);

    // -- Save the Object
    objects = new ArrayList<Object>();
    objects.add(pkg1);
    objects.add(pkg2);

    resp = ((LifeCycleManagerImpl) getLCM()).saveObjects(objects, saveObjectsSlots);
    JAXRUtility.checkBulkResponse(resp);
    System.out.println("Added Registry Package with Id " + uuid2);

    // Remove the package.
    pkg1.removeRegistryObject(pkg2);
    // -- Save the Object
    objects = new ArrayList<Object>();
    objects.add(pkg1);

    resp = ((LifeCycleManagerImpl) getLCM()).saveObjects(objects, saveObjectsSlots);
    JAXRUtility.checkBulkResponse(resp);
    System.out.println("Removed Registry Package with Id " + uuid2);

    // Get 'HasMember' associations of pkg1.
    ArrayList<String> associationTypes = new ArrayList<String>();
    associationTypes.add(bu.CANONICAL_ASSOCIATION_TYPE_ID_HasMember);

    resp = getBQM().findAssociations(null, uuid1, null, associationTypes);
    JAXRUtility.checkBulkResponse(resp);

    Collection<?> coll = resp.getCollection();

    if (coll.size() != 0) {
        Iterator<?> iter = coll.iterator();

        while (iter.hasNext()) {
            Association ass = (Association) iter.next();

            System.err.println("Association: " + ass.getKey().getId() + "; sourceObject: "
                    + ass.getSourceObject().getKey().getId() + "; targetObject: "
                    + ass.getTargetObject().getKey().getId());
        }
    }

    assertEquals("uuid1 should not be the sourceObject in any HasMember associations.", 0, coll.size());

    objects = new ArrayList<Object>();
    objects.add(pkg1.getKey());
    objects.add(pkg2.getKey());
    if (coll.size() != 0) {
        Iterator<?> itr = coll.iterator();
        while (itr.hasNext()) {
            RegistryObject ro = (RegistryObject) itr.next();
            objects.add(ro.getKey());
        }
    }
    resp = getLCM().deleteObjects(objects);
    JAXRUtility.checkBulkResponse(resp);
}

From source file:it.cnr.icar.eric.client.xml.registry.LifeCycleManagerImpl.java

/**
 * Changes the owner of one or more objects.
 * //w  ww.  j a  v  a 2 s  . c o  m
 * @param keys
 *            a Collection of keys for the objects to be
 * @param newOwner
 *            a Collection of keys for the objects to be deprecated
 * 
 * @return a BulkResponse containing the Collection of keys for those
 *         objects that had their owner changed successfully and any
 *         JAXRException that was encountered in case of partial commit
 * 
 * @throws JAXRException
 *             if the JAXR provider encounters an internal error
 */
public BulkResponse changeObjectsOwner(Collection<?> keys, AdhocQueryImpl query1, String newOwner)
        throws JAXRException {
    BulkResponseImpl response = null;
    @SuppressWarnings("unused")
    List<ObjectRefType> orl = createObjectRefList(keys);

    try {
        DeclarativeQueryManager dqm = getRegistryService().getDeclarativeQueryManager();

        org.oasis.ebxml.registry.bindings.lcm.RelocateObjectsRequest req = lcmFac
                .createRelocateObjectsRequest();
        ClientRequestContext context = new ClientRequestContext(
                "it.cnr.icar.eric.client.xml.registry.LifeCycleManagerImpl:changeObjectsOwner", req);

        // Create and set query
        String queryStr = "SELECT ro.* from RegistryObject ro WHERE ";

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

        while (iter.hasNext()) {
            String roID = ((Key) iter.next()).getId();
            queryStr += "ro.id = '" + roID + "'";
            if (iter.hasNext()) {
                queryStr += " OR ";
            }
        }

        AdhocQueryType ebAdhocQueryType = bu.createAdhocQueryType(queryStr);
        req.setAdhocQuery(ebAdhocQueryType);

        // Set owner at source
        ObjectRefType sourceOwnerRef = rimFac.createObjectRefType();
        sourceOwnerRef.setId(it.cnr.icar.eric.common.Utility.getInstance().createId()); // Just
        // a
        // dummy
        // id
        // for
        // now
        // will
        // do.
        req.setOwnerAtSource(sourceOwnerRef);

        // Set owner at destination
        ObjectRefType newOwnerObj = rimFac.createObjectRefType();
        newOwnerObj.setId(newOwner);
        req.setOwnerAtDestination(newOwnerObj);

        // Get registry
        String registryQueryStr = "SELECT r.* from Registry r ";

        Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, registryQueryStr);

        // make JAXR request
        javax.xml.registry.BulkResponse registryResponse = dqm.executeQuery(query);

        JAXRUtility.checkBulkResponse(registryResponse);

        // TODOD: Following is dangerous assumption as there may be replica
        // Registry instances
        // representing other registries. SHould iterate over all and find
        // the first one
        // where home attribute is undefined.
        RegistryObject registry = (RegistryObject) JAXRUtility.getFirstObject(registryResponse.getCollection());

        ObjectRefType registryRef = rimFac.createObjectRefType();
        registryRef.setId(registry.getKey().getId());
        req.setSourceRegistry(registryRef);
        req.setDestinationRegistry(registryRef);

        JAXRUtility.addCreateSessionSlot(req, regService.getConnection());
        // Submit the request
        RegistryResponseType ebResp = serverLCM.relocateObjects(context);
        response = new BulkResponseImpl(this, ebResp, null);

        // Now setCollection with ids of objects saved
        setKeysOnBulkResponse(context, response);
    } catch (javax.xml.bind.JAXBException e) {
        log.debug(e);
        throw new JAXRException(e);
    }

    return response;
}

From source file:it.cnr.icar.eric.client.xml.registry.LifeCycleManagerImpl.java

private void initializeObjectTypesMap() {
    try {//www  . j ava2s. c o m
        DeclarativeQueryManager dqm = getRegistryService().getDeclarativeQueryManager();
        //         String queryStr = "SELECT children.* FROM ClassificationNode children, ClassificationNode parent where (parent.path LIKE '/"
        //               + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType
        //               + "/RegistryObject%') AND (parent.path NOT LIKE '/"
        //               + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType
        //               + "/RegistryObject/ExtrinsicObject/%') AND parent.id = children.parent";
        //         Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);

        Query query = SQLQueryProvider.initializeObjectTypesMap(dqm);

        BulkResponse resp = dqm.executeQuery(query);

        if ((resp != null) && (!(resp.getStatus() == JAXRResponse.STATUS_SUCCESS))) {
            Collection<?> exceptions = resp.getExceptions();

            if (exceptions != null) {
                Iterator<?> iter = exceptions.iterator();

                while (iter.hasNext()) {
                    Exception e = (Exception) iter.next();
                    e.printStackTrace();
                }
            }

            return;
        }

        objectTypesMap = new HashMap<String, Concept>();

        Collection<?> concepts = resp.getCollection();
        Iterator<?> iter = concepts.iterator();

        while (iter.hasNext()) {
            Concept concept = (Concept) iter.next();
            String value = concept.getValue();

            if (value.equals("ClassificationNode")) {
                value = "Concept";
            }

            objectTypesMap.put(value, concept);
        }
    } catch (JAXRException e) {
        e.printStackTrace();
    }
}

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

@SuppressWarnings("unchecked")
public void handleRegistryObjects(BulkResponse bResponse) throws Exception {
    handleRegistryObjects(bResponse.getCollection());
    try {//from ww w .ja  v a2s .c om
        RegistryResponseType resp = ((BulkResponseImpl) bResponse).getRegistryResponse();
        int maxResults = ((AdhocQueryResponse) resp).getTotalResultCount().intValue();
        getScrollerBean().setTotalResultCount(maxResults);
    } catch (Throwable t) {
        String msg = WebUIResourceBundle.getInstance().getString("message.couldNotSetTotalResultCount");
        msg = msg + ". " + WebUIResourceBundle.getInstance().getString("checkLogForDetails");
        OutputExceptions.error(log, msg, t);
    }
}

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

public void appendRegistryObjects(BulkResponse bResponse) throws Exception {
    this.doDeleteFile();
    @SuppressWarnings("unchecked")
    List<RegistryObjectBean> beans = createRegistryObjectBeans(bResponse.getCollection());
    createRegistryObjectBeansLookup(beans);
    setRegistryObjectBeans(beans);//from  ww  w. j  a  v  a 2  s. c o m
    try {
        RegistryResponseType resp = ((BulkResponseImpl) bResponse).getRegistryResponse();
        int maxResults = ((AdhocQueryResponse) resp).getTotalResultCount().intValue();
        getScrollerBean().setTotalResultCount(maxResults);
    } catch (Throwable t) {
        String msg = WebUIResourceBundle.getInstance().getString("message.couldNotSetTotalResultCount");
        msg = msg + ". " + WebUIResourceBundle.getInstance().getString("checkLogForDetails");
        OutputExceptions.error(log, msg, t);
    }
}

From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerImpl.java

/**
 * Saves one or more Objects to the registry. An object may be a
 * RegistryObject  subclass instance. If an object is not in the registry,
 * it is created in the registry.  If it already exists in the registry
 * and has been modified, then its  state is updated (replaced) in the
 * registry//w ww .  j a v a  2s . com
 * <p/>
 * TODO:Check if juddi can provide a facility to store a collection of heterogenous
 * objects
 * <p/>
 * TODO - does this belong here?  it's really an overload of
 * LifecycleManager.saveObjects, but all the help we need
 * like saveOrganization() is up here...
 *
 * @param col
 * @return a BulkResponse containing the Collection of keys for those objects
 *         that were saved successfully and any SaveException that was encountered
 *         in case of partial commit
 * @throws JAXRException
 */
public BulkResponse saveObjects(Collection col) throws JAXRException {

    Iterator iter = col.iterator();

    LinkedHashSet<Object> suc = new LinkedHashSet<Object>();
    Collection<Exception> exc = new ArrayList<Exception>();

    while (iter.hasNext()) {
        RegistryObject reg = (RegistryObject) iter.next();

        BulkResponse br = null;

        Collection<RegistryObject> c = new ArrayList<RegistryObject>();
        c.add(reg);

        if (reg instanceof javax.xml.registry.infomodel.Association) {
            br = saveAssociations(c, true);
        } else if (reg instanceof javax.xml.registry.infomodel.ClassificationScheme) {
            br = saveClassificationSchemes(c);
        } else if (reg instanceof javax.xml.registry.infomodel.Concept) {
            br = saveConcepts(c);
        } else if (reg instanceof javax.xml.registry.infomodel.Organization) {
            br = saveOrganizations(c);
        } else if (reg instanceof javax.xml.registry.infomodel.Service) {
            br = saveServices(c);
        } else if (reg instanceof javax.xml.registry.infomodel.ServiceBinding) {
            br = saveServiceBindings(c);
        } else {
            throw new JAXRException("Delete Operation for " + reg.getClass() + " not implemented by Scout");
        }

        if (br.getCollection() != null) {
            suc.addAll(br.getCollection());
        }

        if (br.getExceptions() != null) {
            exc.addAll(br.getExceptions());
        }
    }

    BulkResponseImpl bulk = new BulkResponseImpl();

    /*
     *  TODO - what is the right status?
     */
    bulk.setStatus(JAXRResponse.STATUS_SUCCESS);

    bulk.setCollection(suc);
    bulk.setExceptions(exc);

    return bulk;
}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerImpl.java

public BulkResponse findAssociations(Collection findQualifiers, String sourceObjectId, String targetObjectId,
        Collection associationTypes) throws JAXRException {
    //TODO: Currently we just return all the Association objects owned by the caller
    IRegistry registry = (IRegistry) registryService.getRegistry();
    try {//from  w w w  .  j a  v  a  2 s . co  m
        ConnectionImpl con = ((RegistryServiceImpl) getRegistryService()).getConnection();
        AuthToken auth = this.getAuthToken(con, registry);
        PublisherAssertions result = null;
        try {
            result = registry.getPublisherAssertions(auth.getAuthInfo());
        } catch (RegistryException rve) {
            String username = getUsernameFromCredentials(con.getCredentials());
            if (AuthTokenSingleton.getToken(username) != null) {
                AuthTokenSingleton.deleteAuthToken(username);
            }
            auth = getAuthToken(con, registry);
            result = registry.getPublisherAssertions(auth.getAuthInfo());
        }

        List<PublisherAssertion> publisherAssertionList = result.getPublisherAssertion();
        LinkedHashSet<Association> col = new LinkedHashSet<Association>();
        for (PublisherAssertion pas : publisherAssertionList) {
            String sourceKey = pas.getFromKey();
            String targetKey = pas.getToKey();

            if ((sourceObjectId == null || sourceObjectId.equals(sourceKey))
                    && (targetObjectId == null || targetObjectId.equals(targetKey))) {
                Collection<Key> orgcol = new ArrayList<Key>();
                orgcol.add(new KeyImpl(sourceKey));
                orgcol.add(new KeyImpl(targetKey));
                BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
                Association asso = ScoutUddiJaxrHelper.getAssociation(bl.getCollection(),
                        registryService.getBusinessLifeCycleManager());
                KeyedReference keyr = pas.getKeyedReference();
                Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
                c.setName(new InternationalStringImpl(keyr.getKeyName()));
                c.setKey(new KeyImpl(keyr.getTModelKey()));
                c.setValue(keyr.getKeyValue());
                asso.setAssociationType(c);
                col.add(asso);
            }

        }
        return new BulkResponseImpl(col);
    } catch (RegistryException e) {
        throw new JAXRException(e);
    }
}