Allocating a Work Item — Service Connector API Example (Java)

An example is provided that illustrates allocating a work item to a target resource, using the method calls available in the Java Service Connector API.

The step numbers in the comments correspond to the steps shown in Allocating a Work Item.

	private void allocateWorkItemExample()
	{
		// Setup the ManagedObjectID for the work item we want the offer set for
		ManagedObjectID id = ManagedObjectID.Factory.newInstance();
		id.setId(10);
		try
		{
			// Step 1: Get the offer set GUIDs for the work item
			String[] offerGUIDs = serviceConnectorInstance.getOfferSet(id);
			if (offerGUIDs != null && offerGUIDs.length > 0)
			{
				// Step 2: Get the associated resources for the offer set GUIDs
				XmlLdapEntity[] entities = serviceConnectorInstance.listAssociatedResources(offerGUIDs, 0, 100);
				if (entities != null && entities.length > 0)
				{
					// Step 3: For this example allocate the work item to the first GUID we found
					serviceConnectorInstance.allocateWorkItem(new ManagedObjectID[]{id},
							new String[]{entities[0].getGuid()});
					// Now re-offer the work item to put it back to how we found it
					serviceConnectorInstance.unallocateWorkItem(new ManagedObjectID[]{id});
				}
			}
		}
		catch (InvalidVersionFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (InvalidWorkItemFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (com.tibco.n2.brm.services.InternalServiceFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (InvalidEntityReferenceFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (com.tibco.n2.de.services.InternalServiceFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (InvalidOrgModelVersionFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (InvalidEntityFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (com.tibco.n2.brm.services.SecurityFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}