Example usage for javax.xml.registry.infomodel RegistryPackage removeRegistryObject

List of usage examples for javax.xml.registry.infomodel RegistryPackage removeRegistryObject

Introduction

In this page you can find the example usage for javax.xml.registry.infomodel RegistryPackage removeRegistryObject.

Prototype

void removeRegistryObject(RegistryObject registryObject) throws JAXRException;

Source Link

Document

Removes a child RegistryObject from membership.

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./*ww w  .j  av a 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);
}