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.xml.registry.InfomodelFactoryTest.java

/**
 * Test lcm.create, lcm.save and query of extended Association
 *///from   www .ja v a  2 s  .c  o  m
public void testExtendedAssociationLCM() throws Exception {
    System.out.println("\ntestExtendedAssociationLCM");

    Object o;
    @SuppressWarnings("unused")
    InfomodelFactory extUtil = InfomodelFactory.getInstance();

    Concept parentConcept = (Concept) bqm.getRegistryObject(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Association,
            "ClassificationNode");
    Concept myAssociationType = lcm.createConcept(parentConcept, "MyAssociation", "MyAssociation");
    myAssociationType.setKey(lcm.createKey(ASS_EXT_UUID));

    try {
        BulkResponse br;
        // Save concept and update it, to get the path
        br = lcm.saveObjects(Collections.singleton(myAssociationType));
        assertResponseSuccess(br);
        Query q = dqm.createQuery(QueryImpl.QUERY_TYPE_SQL,
                "select * from ClassificationNode where id = '" + ASS_EXT_UUID + "'");
        br = dqm.executeQuery(q);
        assertResponseSuccess(br);
        myAssociationType = (Concept) br.getCollection().iterator().next();

        // test lcm.createObject(Concept)
        o = lcm.createObject(myAssociationType);
        assertNotNull(o);
        assertTrue("Association extensions must extend AssociationImpl", o instanceof AssociationImpl);
        assertEquals("Should have been default class", ASS_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyAssociation", myAssociationType,
                ((Association) o).getAssociationType());

        // test lcm.createObject(String)
        o = lcm.createObject(ASS_NICKNAME);
        assertNotNull(o);
        assertTrue("Association extensions must extend AssociationImpl", o instanceof AssociationImpl);
        assertEquals("Should have been default class", ASS_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyAssociation", myAssociationType,
                ((Association) o).getAssociationType());

        // test lcm.createAssociation
        o = lcm.createAssociation(myAssociationType);
        assertNotNull(o);
        assertTrue("Association extensions must extend AssociationImpl", o instanceof AssociationImpl);
        assertEquals("Should have been default class", ASS_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyAssociation", myAssociationType,
                ((Association) o).getAssociationType());
        ((RegistryObject) o).setKey(lcm.createKey(ASS_TEST_UUID));

        // Association needs a source and a target
        RegistryObject target = lcm.createExtrinsicObject();
        target.setKey(lcm.createKey(EO_TEST_UUID));
        assertNotNull(target);
        ((AssociationImpl) o).setTargetObject(target);
        ((AssociationImpl) o).setSourceObject(parentConcept);

        ArrayList<Object> objects = new ArrayList<Object>();
        objects.add(o);
        objects.add(target);
        br = lcm.saveObjects(objects);
        assertResponseSuccess(br);
        q = dqm.createQuery(QueryImpl.QUERY_TYPE_SQL,
                "select * from Association where id = '" + ASS_TEST_UUID + "'");
        br = dqm.executeQuery(q);
        assertResponseSuccess(br);
        o = br.getCollection().iterator().next();
        assertEquals("Should have been default class", ASS_EXT_CLASSNAME, o.getClass().getName());
    } finally {
        // cleanup
        deleteIfExist(ASS_EXT_UUID, LifeCycleManager.ASSOCIATION);
        deleteIfExist(EO_TEST_UUID, LifeCycleManager.EXTRINSIC_OBJECT);
        deleteIfExist(ASS_TEST_UUID, LifeCycleManager.ASSOCIATION);
    }
}

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

/**
 * Test lcm.create, lcm.save and query of extended ExtrinsicObject
 *///from   w  w  w .  java 2  s  .  c o  m
public void testExtendedExtrinsicObjectLCM() throws Exception {
    System.out.println("\ntestExtendedExtrinsicObjectLCM");

    Object o;
    @SuppressWarnings("unused")
    InfomodelFactory extUtil = InfomodelFactory.getInstance();

    Concept parentConcept = (Concept) bqm
            .getRegistryObject(BindingUtility.CANONICAL_OBJECT_TYPE_ID_ExtrinsicObject, "ClassificationNode");
    Concept myExtrinsicObjectType = lcm.createConcept(parentConcept, "MyExtrinsicObject", "MyExtrinsicObject");
    myExtrinsicObjectType.setKey(lcm.createKey(EO_EXT_UUID));

    try {
        BulkResponse br;
        // Save concept and update it, to get the path
        br = lcm.saveObjects(Collections.singleton(myExtrinsicObjectType));
        assertResponseSuccess(br);
        Query q = dqm.createQuery(QueryImpl.QUERY_TYPE_SQL,
                "select * from ClassificationNode where id = '" + EO_EXT_UUID + "'");
        br = dqm.executeQuery(q);
        assertResponseSuccess(br);
        myExtrinsicObjectType = (Concept) br.getCollection().iterator().next();

        // test lcm.createObject(Concept)
        o = lcm.createObject(myExtrinsicObjectType);
        assertNotNull(o);
        assertTrue("ExtrinsicObject extensions must extend ExtrinsicObjectImpl",
                o instanceof ExtrinsicObjectImpl);
        assertEquals("Should have been default class", EO_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyExtrinsicObject", myExtrinsicObjectType,
                ((ExtrinsicObject) o).getObjectType());

        // test lcm.createObject(String)
        o = lcm.createObject(EO_NICKNAME);
        assertNotNull(o);
        assertTrue("ExtrinsicObject extensions must extend ExtrinsicObjectImpl",
                o instanceof ExtrinsicObjectImpl);
        assertEquals("Should have been default class", EO_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyExtrinsicObject", myExtrinsicObjectType,
                ((ExtrinsicObject) o).getObjectType());

        // test lcm.createExtrinsicObject
        o = lcm.createExtrinsicObject(myExtrinsicObjectType);
        assertNotNull(o);
        assertTrue("ExtrinsicObject extensions must extend ExtrinsicObjectImpl",
                o instanceof ExtrinsicObjectImpl);
        assertEquals("Should have been default class", EO_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyExtrinsicObject", myExtrinsicObjectType,
                ((ExtrinsicObject) o).getObjectType());
        ((RegistryObject) o).setKey(lcm.createKey(EO_TEST_UUID));

        br = lcm.saveObjects(Collections.singleton(myExtrinsicObjectType));
        assertResponseSuccess(br);

        br = lcm.saveObjects(Collections.singleton(o));
        assertResponseSuccess(br);
        q = dqm.createQuery(QueryImpl.QUERY_TYPE_SQL,
                "select * from ExtrinsicObject where id = '" + EO_TEST_UUID + "'");
        br = dqm.executeQuery(q);
        assertResponseSuccess(br);
        o = br.getCollection().iterator().next();
        assertEquals("Should have been default class", EO_EXT_CLASSNAME, o.getClass().getName());
    } finally {
        // cleanup
        deleteIfExist(EO_EXT_UUID, LifeCycleManager.EXTRINSIC_OBJECT);
        deleteIfExist(EO_TEST_UUID, LifeCycleManager.EXTRINSIC_OBJECT);
    }
}

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

/**
 * Find all Concept that match the path specified. For JAXR 2.0??
 *
 * <p><DL><DT><B>Capability Level: 0 </B></DL>
 *
 * @param path Is a canonical path expression as defined in the JAXR specification that identifies the Concept.
 *
 */// w  ww. ja v a2  s. c  om
@SuppressWarnings("rawtypes")
public Collection findConceptsByPath(String path) throws JAXRException {
    //        String likeOrEqual = "=";
    //
    //        if (path.indexOf('%') != -1) {
    //            likeOrEqual = LIKE_KEYWORD;
    //        }
    //
    //        Query query = dqm.createQuery(Query.QUERY_TYPE_SQL,
    //                "SELECT cn.* from ClassificationNode cn WHERE cn.path " +
    //                likeOrEqual + " '" + path + "' ORDER BY cn.path ASC");
    //        BulkResponse resp = dqm.executeQuery(query);

    Query query = SQLQueryProvider.findConceptsByPath(dqm, path);
    BulkResponse resp = dqm.executeQuery(query);

    return resp.getCollection();
}

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

/**
 * Find a ClassificationScheme by name based on the specified name pattern.
 *
 *
 * <p><DL><DT><B>Capability Level: 0 </B></DL>
 *
 * @param namePattern Is a String that is a partial or full
 * name pattern with wildcard searching as specified by the SQL-92 LIKE
 * specification./*from  w  w w . ja v  a 2 s  .  c  om*/
 *
 * @return The ClassificationScheme matching the namePattern. If none match
 * return null. If multiple match then throw an InvalidRequestException.
 *
 */
public ClassificationScheme findClassificationSchemeByName(
        @SuppressWarnings("rawtypes") Collection findQualifiers, String namePattern) throws JAXRException {
    Collection<String> namePatterns = new ArrayList<String>();
    namePatterns.add(namePattern);

    Query query = createQueryByName(findQualifiers, "ClassificationScheme", namePatterns);
    BulkResponse br = dqm.executeQuery(query);
    query = addOrderBy(query, findQualifiers);

    Iterator<?> i = br.getCollection().iterator();
    ClassificationScheme cs = null;

    if (i.hasNext()) {
        cs = (ClassificationScheme) i.next();
    }

    // needs to check if more then 1 return and raise InvalidRequestException
    if (i.hasNext()) {
        throw new InvalidRequestException(JAXRResourceBundle.getInstance()
                .getString("message.error.call.not.match.ClassificationScheme"));
    }

    return cs;
}

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

@SuppressWarnings("unchecked")
void update(BulkResponse response) {
    Collection<Object> registryObjects = new ArrayList<Object>();
    try {/*from  ww  w.  ja v  a2s  . c om*/
        // check for errors
        Collection<?> exceptions = response.getExceptions();
        if (exceptions != null) {
            String errMsg = resourceBundle.getString("error.registryRequest");
            Iterator<?> iter = exceptions.iterator();
            Exception exception = null;
            while (iter.hasNext()) {
                exception = (Exception) iter.next();
                RegistryBrowser.displayError(errMsg, exception);
            }
        }

        // check for objects
        // collection may be empty if there were errors
        registryObjects.addAll(response.getCollection());
        //Get the most specific object type that is common to all RegistryObjects
        Concept commonObjectType = UIUtility.getInstance().getCommonObjectType(registryObjects);
        //Dynamically update model configuration basd upon objectType
        updateConfiguration(commonObjectType);
    } catch (JAXRException e) {
        RegistryBrowser.displayError(e);
    }

    if (registryObjects.isEmpty()) {
        JOptionPane.showMessageDialog(null, resourceBundle.getString("message.noObjects"),
                resourceBundle.getString("title.registryBrowser.java"), JOptionPane.INFORMATION_MESSAGE);
    }

    setRegistryObjects(registryObjects);
}

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

@SuppressWarnings("unchecked")
public Collection<RegistryObject> getAllAssociations() throws JAXRException {
    if (isNew()) {
        // ??eeg Still can have client side associated objects!
        // Return an empty Collection instead of null
        return new ArrayList<RegistryObject>();
    }//from  ww w  .j  a  v a  2  s  .c  o  m

    String id = getKey().getId();
    //        String queryStr = "SELECT ass.* FROM Association ass WHERE sourceObject = '" +
    //            id + "' OR targetObject = '" + id + "'" + " ORDER BY " +
    //            "sourceObject, targetObject, associationType";
    //        Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);

    Query query = SQLQueryProvider.getAllAssociations(dqm, id);

    BulkResponse response = dqm.executeQuery(query);
    checkBulkResponseExceptions(response);

    return response.getCollection();
}

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

@SuppressWarnings("unchecked")
public Collection<RegistryObject> getAuditTrail() throws JAXRException {
    Collection<RegistryObject> auditTrail = null;
    if (!isNew()) {
        //          String queryStr = "SELECT ae.* FROM AuditableEvent ae, AffectedObject ao, RegistryObject ro WHERE ro.lid='" + lid + "' AND ro.id = ao.id AND ao.eventId = ae.id ORDER BY ae.timeStamp_ ASC";
        //          Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);

        Query query = SQLQueryProvider.getAuditTrail(dqm, lid);

        BulkResponse response = dqm.executeQuery(query);

        checkBulkResponseExceptions(response);
        auditTrail = response.getCollection();
    }//from   w  w w  .j  a v  a2 s.c  o  m

    if (auditTrail == null) {
        auditTrail = new ArrayList<RegistryObject>();
    }

    return auditTrail;
}

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

@SuppressWarnings("unchecked")
public Collection<RegistryObject> getAssociatedObjects() throws JAXRException {
    Collection<RegistryObject> assObjects = null;
    if (isNew()) {
        assObjects = new ArrayList<RegistryObject>();
        if (associations != null) {
            Iterator<Association> iter = associations.iterator();
            while (iter.hasNext()) {
                Association ass = iter.next();
                assObjects.add(ass.getTargetObject());
            }/* w ww. j a v  a  2s  .  c o m*/
        }
    } else {
        String id = getKey().getId();
        //            String queryStr = "SELECT ro.* FROM RegistryObject ro, Association ass WHERE ass.sourceObject = '" +
        //                id + "' AND ass.targetObject = ro.id";
        //            Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);

        Query query = SQLQueryProvider.getAssociatedObjects(dqm, id);

        BulkResponse response = dqm.executeQuery(query);
        checkBulkResponseExceptions(response);
        assObjects = response.getCollection();
    }

    return assObjects;
}

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

public Collection<Association> getAssociations() throws JAXRException {
    if (associations == null) {
        associations = new HashSet<Association>();

        //If existing object then now is the time to do lazy fetch from server
        if (!isNew()) {
            // Return Collection from server
            String id = getKey().getId();
            String queryStr = "SELECT ass.* FROM Association ass WHERE sourceObject = '" + id + "'";
            Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);
            BulkResponse response = dqm.executeQuery(query);
            checkBulkResponseExceptions(response);
            addAssociations(response.getCollection());
        }//from w  w  w .j av a  2 s.  c o  m
    }

    return associations;
}

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

public Collection<ExternalLink> getExternalLinks() throws JAXRException {
    if (externalLinks == null) {
        externalLinks = new HashSet<ExternalLink>();

        //If existing object then now is the time to do lazy fetch from server
        if (!isNew()) {
            String id = getId();//  ww  w. jav  a2  s  . c om
            //                String queryStr =
            //                    "SELECT el.* FROM ExternalLink el, Association ass WHERE ass.targetObject = '" +
            //                    id + "' AND ass.associationType = '" +
            //                    BindingUtility.CANONICAL_ASSOCIATION_TYPE_ID_ExternallyLinks +
            //                    "' AND ass.sourceObject = el.id ";
            //                Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);

            Query query = SQLQueryProvider.getExternalLinks(dqm, id);

            BulkResponse response = dqm.executeQuery(query);
            checkBulkResponseExceptions(response);
            addExternalLinks(response.getCollection());
        }
    }

    return externalLinks;
}