public static Client createClient()
{
Client client = Client.create();
client.addFilter( new HTTPBasicAuthFilter("admin", "secret" ) );
return client;
}
public static void main( String[] argv )
{
System.out.println(" >> start" );
try {
Client client = createClient();
SimpleCostObject sco = new SimpleCostObject( client );
//
// READ cost objects
//
SimpleCostObjectResultType result = sco.getAsApplicationXml(
SimpleCostObjectResultType.class );
List<SimpleCostObjectType> objs = result.getSimpleCostObject();
for( SimpleCostObjectType co : objs )
System.out.println( " RESULT --> " + co.getCostObjectID() );
//
// UPDATE cost objects
//
SimpleCostObjectRequestType request = new SimpleCostObjectRequestType();
// COST OBJECT #1
SimpleCostObjectType co = new SimpleCostObjectType();
co.setCostObjectID("PROJ1");
co.setCostObjectName("Project Name " + Long.toHexString(System.currentTimeMillis()));
request.getSimpleCostObject().add(co); // add to list on request
// COST OBJECT #2
co = new SimpleCostObjectType();
co.setCostObjectID("PROJ2");
co.setCostObjectName("Project Name " + Long.toHexString(System.currentTimeMillis()));
request.getSimpleCostObject().add(co); // add to list on request
// convert request object
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<SimpleCostObjectRequestType> requestWrapper =
objectFactory.createSimpleCostObjectRequest(request);
result = sco.postApplicationXmlAsApplicationXml(requestWrapper,
SimpleCostObjectResultType.class );
for( ObjectResultType or : result.getObjectResult() )
System.out.println( " UPDATE RESULT --> " + or.getInternalId() );
} catch( Exception e ) {
e.printStackTrace();
} finally {
System.out.println(" << end" );
}
}