Example usage for javax.xml.registry.infomodel Association getKey

List of usage examples for javax.xml.registry.infomodel Association getKey

Introduction

In this page you can find the example usage for javax.xml.registry.infomodel Association getKey.

Prototype

Key getKey() throws JAXRException;

Source Link

Document

Gets the key representing the universally unique ID (UUID) for this object.

Usage

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./* w  w  w  .j  ava  2  s. c  o m*/
 *
 * @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.infomodel.RegistryObjectImpl.java

public void removeAssociation(Association ass) throws JAXRException {
    getAssociations();/*from  ww w .j a  va 2  s.co m*/

    if (associations.contains(ass)) {
        associations.remove(ass);

        //Need to mark as deleted and only remove from server on Save in future.
        //For now leaving as is in order to minimize change.???
        // Remove from server only if Association exists there
        if (!((AssociationImpl) ass).isNew()) {
            // assert(Association must exist on server)
            ArrayList<Key> keys = new ArrayList<Key>();
            keys.add(ass.getKey());

            BulkResponse response = lcm.deleteObjects(keys);
            JAXRException ex = getBulkResponseException(response);

            if (ex != null) {
                throw ex;
            }
        }

        //No need to call setModified(true) since RIM modified object is an Assoociation
        //setModified(true);
    }
}

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

/**
 * DOCUMENT ME!//w  w w. ja v a 2  s  .c o  m
 *
 * @param cell DOCUMENT ME!
 * @param ro DOCUMENT ME!
 *
 * @return ArrayList of GraphCell for the related objects.
 */
private ArrayList<Object> showRelatedObjects(JBGraphCell cell, RegistryObject ro) {
    ArrayList<Object> relatedCells = new ArrayList<Object>();

    if (ro == null) {
        return relatedCells;
    }

    try {
        CellView cellView = getView().getMapping(cell, false);
        Rectangle bounds = cellView.getBounds();

        //Classifications
        Collection<?> classifications = ro.getClassifications();
        DefaultGraphCell groupCell = createGroupFromObjectCollection(classifications);

        if (groupCell != null) {
            connectCells(cell, groupCell, "classifications", false);
            relatedCells.add(groupCell);
        }

        //ExternalIdentifiers
        Collection<?> extIds = ro.getExternalIdentifiers();
        groupCell = createGroupFromObjectCollection(extIds);

        if (groupCell != null) {
            connectCells(cell, groupCell, "externalIdentifiers", false);
            relatedCells.add(groupCell);
        }

        //ExternalLinks
        Collection<?> extLinks = ro.getExternalLinks();
        groupCell = createGroupFromObjectCollection(extLinks);

        if (groupCell != null) {
            connectCells(cell, groupCell, "externalLinks", false);
            relatedCells.add(groupCell);
        }

        /*
           //RegistryPackages
           try {
           Collection pkgs = ro.getRegistryPackages();
           Iterator iter = pkgs.iterator();
           while (iter.hasNext()) {
               RegistryPackage pkg = (RegistryPackage)iter.next();
               if (pkg != null) {
                   JBGraphCell newCell = addRelatedObject(cell, pkg, new Rectangle(0, 0, 50, 50), "HasMember", true);
                   relatedCells.add(newCell);
               }
           }
           } catch (UnsupportedCapabilityException e) {
           }
         **/

        try {
            //Associations
            Collection<?> assocs = ((RegistryObjectImpl) ro).getAllAssociations();
            Iterator<?> iter = assocs.iterator();

            while (iter.hasNext()) {
                Association assoc = (Association) iter.next();
                RegistryObject srcObj = assoc.getSourceObject();
                RegistryObject targetObj = assoc.getTargetObject();
                Concept concept = assoc.getAssociationType();

                String label = "associatedWith";

                if (concept != null) {
                    label = concept.getValue();
                }

                if ((srcObj != null) && (targetObj != null)) {
                    JBGraphCell newCell = null;

                    if (srcObj.getKey().getId().equalsIgnoreCase(ro.getKey().getId())) {
                        //ro is the source, newCell is the target
                        newCell = addRelatedObject(cell, targetObj,
                                new Rectangle(bounds.x + 100, bounds.y, 50, 50), label, false);
                    } else {
                        //ro is the target, newCell is the source
                        newCell = addRelatedObject(cell, srcObj,
                                new Rectangle(bounds.x + 100, bounds.y, 50, 50), label, true);
                    }

                    relatedCells.add(newCell);
                } else {
                    System.err.println(
                            "Invalid association. Source or target is null: " + assoc.getKey().getId());
                }
            }

        } catch (UnsupportedCapabilityException e) {
        }
    } catch (JAXRException e) {
        RegistryBrowser.displayError(e);
    }

    return relatedCells;
}

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

private List<RegistryObjectBean> getAssociationsSearchResultsBeans(RegistryObjectBean roBean)
        throws ClassNotFoundException, NoSuchMethodException, ExceptionInInitializerError, Exception {
    // The objectTypeRefs map is normally populated by a call to ro.getComposedObjects().
    // However, the getComposedObjects() method retrieves all composed objects for the 
    // inspected RO. In terms of Associations, only those where the RO is the source object 
    // are returned. In order to get all Associations, including those where the RO is the
    // target of an Association, you must call RegistryObjectImpl.getAllAssociations().
    Collection<RegistryObject> associations = ((RegistryObjectImpl) roBean.getRegistryObject())
            .getAllAssociations();//from w ww.ja va 2s . c o  m
    // check if association is valid to list in association tab of
    // details panel.
    if (associations != null) {
        associations = this.filterValidAssociation(associations);
    }
    if (associations == null) {
        return null;
    }
    int numAssociations = associations.size();
    @SuppressWarnings("unused")
    ArrayList<Object> list = new ArrayList<Object>(numAssociations);

    Iterator<RegistryObject> roItr = associations.iterator();
    if (log.isDebugEnabled()) {
        log.debug("Query results: ");
    }

    String objectType = "Association";
    int numCols = 2;
    // Replace ObjectType with Id. TODO - formalize this convention
    List<RegistryObjectBean> roBeans = new ArrayList<RegistryObjectBean>(numAssociations);
    for (@SuppressWarnings("unused")
    int i = 0; roItr.hasNext(); i++) {
        Association association = (Association) roItr.next();
        String header = null;
        Object columnValue = null;
        @SuppressWarnings("unused")
        ArrayList<Object> srvbHeader = new ArrayList<Object>(numCols);
        ArrayList<SearchResultValueBean> searchResultValueBeans = new ArrayList<SearchResultValueBean>(numCols);

        header = WebUIResourceBundle.getInstance().getString("Details");
        columnValue = association.getKey().getId();
        searchResultValueBeans.add(new SearchResultValueBean(header, columnValue));

        header = WebUIResourceBundle.getInstance().getString("Source Object");
        columnValue = association.getSourceObject().getKey().getId();
        searchResultValueBeans.add(new SearchResultValueBean(header, columnValue));

        header = WebUIResourceBundle.getInstance().getString("Target Object");
        columnValue = association.getTargetObject().getKey().getId();
        searchResultValueBeans.add(new SearchResultValueBean(header, columnValue));

        header = WebUIResourceBundle.getInstance().getString("Type");
        columnValue = association.getAssociationType();
        searchResultValueBeans.add(new SearchResultValueBean(header, columnValue));

        RegistryObjectBean srb = new RegistryObjectBean(searchResultValueBeans, roBean.getRegistryObject(),
                objectType, association, false);
        roBeans.add(srb);
    }
    return roBeans;
}

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

public BulkResponse saveAssociations(Collection associations, boolean replace) throws JAXRException {
    BulkResponseImpl bulk = new BulkResponseImpl();
    PublisherAssertion[] sarr = new PublisherAssertion[associations.size()];

    Collection<Key> coll = new ArrayList<Key>();
    Collection<Exception> exceptions = new ArrayList<Exception>();

    Iterator iter = associations.iterator();
    int currLoc = 0;
    while (iter.hasNext()) {

        Association association = (Association) iter.next();
        association.getSourceObject();//from  w w  w  .  j av a2  s .  c o m
        PublisherAssertion pa = ScoutJaxrUddiHelper.getPubAssertionFromJAXRAssociation(association);
        sarr[currLoc] = pa;
        currLoc++;

        // Save PublisherAssertion
        PublisherAssertions bd = null;
        try {
            bd = (PublisherAssertions) executeOperation(sarr, "SAVE_ASSOCIATION");
        } catch (RegistryException e) {
            exceptions.add(new SaveException(e));
            bulk.setExceptions(exceptions);
            bulk.setStatus(JAXRResponse.STATUS_FAILURE);
            return bulk;
        }
        if (bd != null) {
            List<PublisherAssertion> publisherAssertionList = bd.getPublisherAssertion();
            PublisherAssertion[] keyarr = new PublisherAssertion[publisherAssertionList.size()];
            publisherAssertionList.toArray(keyarr);

            for (int i = 0; keyarr != null && i < keyarr.length; i++) {
                PublisherAssertion result = (PublisherAssertion) keyarr[i];
                KeyedReference keyr = result.getKeyedReference();
                Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
                c.setName(new InternationalStringImpl(keyr.getKeyName()));
                c.setKey(new KeyImpl(keyr.getTModelKey()));
                c.setValue(keyr.getKeyValue());
                association.setAssociationType(c);
                coll.add(association.getKey());
            }
        }
    }
    bulk.setCollection(coll);
    bulk.setExceptions(exceptions);

    return bulk;
}

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

public void unConfirmAssociation(Association assoc) throws JAXRException, InvalidRequestException {
    //TODO//from   w  ww  . ja va 2s  . co m
    //Delete it from the UDDI registry
    Collection<Key> col = new ArrayList<Key>();
    col.add(assoc.getKey());
    BulkResponse br = this.deleteAssociations(col);
    if (br.getExceptions() != null)
        throw new JAXRException("UnConfiming the Association Failed");
}

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

public BulkResponse saveAssociations(Collection associations, boolean replace) throws JAXRException {
    BulkResponseImpl bulk = new BulkResponseImpl();
    PublisherAssertion[] sarr = new PublisherAssertion[associations.size()];

    Collection<Key> coll = new ArrayList<Key>();
    Collection<Exception> exceptions = new ArrayList<Exception>();

    Iterator iter = associations.iterator();
    int currLoc = 0;
    while (iter.hasNext()) {

        Association association = (Association) iter.next();
        association.getSourceObject();//from   w w w .  java 2 s  . co  m
        PublisherAssertion pa = ScoutJaxrUddiV3Helper.getPubAssertionFromJAXRAssociation(association);
        sarr[currLoc] = pa;
        currLoc++;

        // Save PublisherAssertion
        PublisherAssertions bd = null;
        try {
            bd = (PublisherAssertions) executeOperation(sarr, "SAVE_ASSOCIATION");
        } catch (RegistryV3Exception e) {
            exceptions.add(new SaveException(e));
            bulk.setExceptions(exceptions);
            bulk.setStatus(JAXRResponse.STATUS_FAILURE);
            return bulk;
        }
        if (bd != null) {
            List<PublisherAssertion> publisherAssertionList = bd.getPublisherAssertion();
            PublisherAssertion[] keyarr = new PublisherAssertion[publisherAssertionList.size()];
            publisherAssertionList.toArray(keyarr);

            for (int i = 0; keyarr != null && i < keyarr.length; i++) {
                PublisherAssertion result = (PublisherAssertion) keyarr[i];
                KeyedReference keyr = result.getKeyedReference();
                Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
                c.setName(new InternationalStringImpl(keyr.getKeyName()));
                c.setKey(new KeyImpl(keyr.getTModelKey()));
                c.setValue(keyr.getKeyValue());
                association.setAssociationType(c);
                coll.add(association.getKey());
            }
        }
    }
    bulk.setCollection(coll);
    bulk.setExceptions(exceptions);

    return bulk;
}