Dashboard > Metasoft Development Network > Welcome to Metasoft Web Services > Java
  Metasoft Development Network Log In | Sign Up   View a printable version of the current page.  
  Java
Added by Brant Levinson, last edited by Brant Levinson on Aug 02, 2009
Labels: 
(None)

Resources

Our Java client uses the CXF library. You can integrate the library easily within your application.
Please also refer to the TestClient.java file within src.gen\com\metasoft\client package.

The following details out the sample class called TestClient.java.

The GetData Method

First, define the class:

public class TestClient {
public static void main(String[] args) {

This main method will execute both the submitData and getData method:

public static void main(String[] args) throws IOException {
submitData();
getData();
}

Define the getData method:

private static void getData() throws IOException{

Then instantiate the ObjectFactory and create the necessary objects to run the query.

ObjectFactory objectFactory = new ObjectFactory();
GetDataType getDataType = objectFactory.createGetDataType();
GetDataType.QueryConstraints queryConstraints = objectFactory.createGetDataTypeQueryConstraints();
PredicateBagType predicateBagType =  objectFactory.createPredicateBagType();
BinaryPredicateType binaryPredicateType = objectFactory.createBinaryPredicateType();

We then specify the field name and value that we want to query in the QName:

javax.xml.namespace.QName qname = new javax.xml.namespace.QName("Title");
binaryPredicateType.setFieldID(qname);
binaryPredicateType.setFieldValue("Bourne");
binaryPredicateType.setTest(tva.transport._2005.BinaryPredicateTestType.CONTAINS);

If you want to query the system for a particular person that has a credit in the item then just enter their name in the FieldValue:

BinaryPredicateType binaryPredicateType2 = objectFactory.createBinaryPredicateType();
javax.xml.namespace.QName qname2 = new javax.xml.namespace.QName("CreditName");
binaryPredicateType2.setFieldID(qname2);
// Put in an Actor's Name 
binaryPredicateType2.setFieldValue("Matt Damon");
binaryPredicateType2.setTest(tva.transport._2005.BinaryPredicateTestType.EQUALS);

We can specify anyone that has credit, here is a Producer:

BinaryPredicateType binaryPredicateType3 = objectFactory.createBinaryPredicateType();
javax.xml.namespace.QName qname3 = new javax.xml.namespace.QName("CreditName");
binaryPredicateType3.setFieldID(qname3);
//Put in Producer's Name
binaryPredicateType3.setFieldValue("Paul Sandberg");
binaryPredicateType3.setTest(tva.transport._2005.BinaryPredicateTestType.EQUALS);

or a Director:

BinaryPredicateType binaryPredicateType4 = objectFactory.createBinaryPredicateType();
javax.xml.namespace.QName qname4 = new javax.xml.namespace.QName("CreditName");
binaryPredicateType4.setFieldID(qname4);
//Put in Director's Name
binaryPredicateType4.setFieldValue("Paul Greengrass");
binaryPredicateType4.setTest(tva.transport._2005.BinaryPredicateTestType.EQUALS);

We then specify if the query is an "AND" or an "OR" query:

BinaryPredicateType binaryPredicateTypes[] = new BinaryPredicateType[1];
binaryPredicateTypes[0] = binaryPredicateType;
predicateBagType.getBinaryPredicate().add(binaryPredicateType);
predicateBagType.setType(tva.transport._2005.PredicateBagTypeType.OR);

Set the the number of items in the arraylist and add in all the predicateBags:

predicateBagType.setBinaryPredicate(new ArrayList<BinaryPredicateType>(3));
predicateBagType.getBinaryPredicate().add(binaryPredicateType);
predicateBagType.getBinaryPredicate().add(binaryPredicateType2);
predicateBagType.getBinaryPredicate().add(binaryPredicateType3);
predicateBagType.getBinaryPredicate().add(binaryPredicateType4);
predicateBagType.setType(tva.transport._2005.PredicateBagTypeType.AND);

We then set the query constraints in the necessary object:

queryConstraints.setPredicateBag(predicateBagType);
getDataType.setQueryConstraints(queryConstraints);

We then specify the tables that we want to query:

RequestedTablesType reqTables = objectFactory.createRequestedTablesType();
RequestedTablesType.Table tableType = objectFactory.createRequestedTablesTypeTable();
tableType.setType("ProgramInformationTable");
reqTables.getTable().add(tableType);

We then setup the getData query:

getDataType.setRequestedTables(reqTables);

We can now create a client and send the query to get the result:

MetasoftTVAServiceImpl metasoftClient = new MetasoftTVAServiceImpl();
GetDataResultType result = metasoftClient.getData(getDataType);

We can now traverse through the array, the return objects will be of object type TVAMain.

if (result.getTVAMain() != null) {

Within the TVAMain, you can use the API to get to subclasses.

Collection prgInfos = result.getTVAMain().getProgramDescription().getProgramInformationTable().getProgramInformation();

We can then iterate through the collection to get the data for display.

for (Iterator i = prgInfos.iterator(); i.hasNext(); ) {
ProgramInformationType prgInfo = (ProgramInformationType)i.next();
if (prgInfo.getBasicDescription().getGenre()!= null) {
genreList = prgInfo.getBasicDescription().getGenre();
}

Get Titles and print out CRID:

System.out.println("Title: " + prgInfo.getBasicDescription().getTitle().get(0).getValue());
System.out.println(prgInfo.getProgramId());

Get Genres:

for (Iterator n = genreList.iterator(); n.hasNext();){
GenreType gentype = (GenreType)n.next();
System.out.println("Genre: " +gentype.getName().getValue());
}

Get the list of Credits:

//Get the list of Credits...
if (prgInfo.getBasicDescription().getCreditsList()!= null){
CreditsListType creditListType = prgInfo.getBasicDescription().getCreditsList();
creditList = creditListType.getCreditsItem();
for (Iterator o = creditList.iterator(); o.hasNext();){
CreditsItemType creditItem =   (CreditsItemType)o.next();
PersonNameType character =  (PersonNameType)creditItem.getPersonNameOrPersonNameIDRefOrOrganizationName().get(0).getValue();
NameComponentType name  = (NameComponentType)character.getGivenNameOrLinkingNameOrFamilyName().get(0).getValue() ;
//Print out the Name and the Role of each...
System.out.println("Name: " + name.getValue());
System.out.println("Role: " + (creditItem.getRole()).substring(creditItem.getRole().lastIndexOf(":") +1));
System.out.println("----------------------------") ;
}

Your output should look similar to this:

Title: The Bourne Ultimatum
crid://nexxusnet.com/TheBourneUltimatum_1
Genre: Action
Genre: Thriller
Name: Matt Damon
Role: ACTOR
----------------------------
Name: Julia Stiles
Role: ACTOR
----------------------------
Name: Joan Allen
Role: ACTOR
----------------------------
Name: David Strathairn
Role: ACTOR
----------------------------
Name: Scott Glenn
Role: ACTOR
----------------------------
Name: Paddy Considine
Role: ACTOR
----------------------------

The SubmitData Method

Define our method as submitData

private static List submitData() {

Create an ExtendedTVAMainType and other necessary objects for the method:

ExtendedTVAMainType mainType = new ExtendedTVAMainType();
ProgramDescriptionType prgDesc = new ProgramDescriptionType();
ProgramInformationTableType prgInfoTable = new ProgramInformationTableType();
ProgramInformationType prgInfo = new ProgramInformationType();
BasicContentDescriptionType basicContent = new BasicContentDescriptionType();
ProgramInformationTableType prgInfoTable1 = new ProgramInformationTableType();
ProgramInformationType prgInfo1 = new ProgramInformationType();
BasicContentDescriptionType basicContent1 = new BasicContentDescriptionType();

Put in the Title of the item:

TitleType title1 = new TitleType();
title1.setValue("Bourne Ultimatum");

You can also define multiple objects, for this example, we are defining a Related Item:

TitleType title = new TitleType();
title.setValue("Bourne Ultimatum (Video Game)");

Put in the Synopsis of each:

SynopsisType synopsisType1 = new SynopsisType();
synopsisType.setValue("The Bourne Ultimatum is a 2007 film based on the Robert Ludlum novel of the same name. A sequel to The Bourne Supremacy
 and the third film of the Bourne Trilogy, it stars Matt Damon reprising his role as Ludlum's signature character, amnesiac CIA assassin Jason Bourne. 
Julia Stiles, David Strathairn, Scott Glenn, Paddy Considine, Edgar Ramirez, Albert Finney, and Joan Allen co-star.");
synopsisType1.setLength(SynopsisLengthType.SHORT);
SynopsisType synopsisType = new SynopsisType();
synopsisType.setValue("Bourne Ultimatum Sigle Player Companion Video Game");
synopsisType.setLength(SynopsisLengthType.SHORT);

Put the item into one or more Genres:

TermNameType termNameType = new TermNameType();
termNameType.setValue("Action");

TermNameType termNameType1 = new TermNameType();
termNameType1.setValue("Thriller");

GenreType genreType = new GenreType();
genreType.setHref("urn:tva:metadata:cs:ContentCS:2005:3.4.6");
genreType.setName(termNameType);
genreType.setType("main");

GenreType genreType = new GenreType();
genreType.setHref("urn:tva:metadata:cs:ContentCS:2005:3.4.6.1");
genreType.setName(termNameType);
genreType.setType("main");

Put in the related item:

ControlledTermType controlledTermType = new ControlledTermType();
controlledTermType.setHref("urn:tva:metadata:cs:HowRelatedCS:2005:10");
TermNameType termNameType3 = new TermNameType();
termNameType3.setValue("For more information");
controlledTermType.setName(termNameType3);

You can assign a CRID, if you don't the system will assign one for you.

MediaLocatorType mediaLocatorType = new MediaLocatorType();
mediaLocatorType.setMediaUri("crid://nexxusnet.com/BourneUltimatumVideoGame_1");

If you choose to add a related item, put the objects in the relatedMaterialType object:

RelatedMaterialType relatedMaterialType = new RelatedMaterialType();
relatedMaterialType.setHowRelated(controlledTermType);
relatedMaterialType.setMediaLocator(mediaLocatorType);

You can define the Parental Guidance like this:

ControlledTermUseType controlledTermUseType = new ControlledTermUseType();
controlledTermUseType.setHref("Parental Guidance Suggested (PG)");
ParentalGuidanceType parentalGuidanceType = new ParentalGuidanceType();
parentalGuidanceType.setParentalRating(controlledTermUseType);

Put a cost in like this:

CostType costType = new CostType();
costType.setValue("2.99");

Put in a publish date like this:

TVATimeType tvaTimeType = new TVATimeType();
tvaTimeType.setTimePoint("JAN-19-2008");

Now put all that information in the BasicContentDescription object:

basicContent.getTitle().add(title);
basicContent1.getTitle().add(title1);
            
basicContent.getSynopsis().add(synopsisType);
basicContent1.getSynopsis().add(synopsisType1);
            
basicContent.getGenre().add(genreType);
basicContent1.getGenre().add(genreType1);
            
basicContent.setDuration(type);
basicContent1.setDuration(type1);
basicContent1.getRelatedMaterial().add(relatedMaterialType);
basicContent1.getParentalGuidance().add(parentalGuidanceType);
basicContent1.setPurchaseList(purchaseListType);
basicContent1.setCost(costType);
basicContent1.setProductionDate(tvaTimeType);

Put that object in the ProgramInformation object:

prgInfo.setBasicDescription(basicContent);
prgInfo1.setBasicDescription(basicContent1);

You can apply the necessary AV attributes:

AVAttributesType avAttributesType = new AVAttributesType();
avAttributesType.setFileSize(new BigInteger("2"));

tva.metadata._2005.VideoAttributesType videoAttributesType = new tva.metadata._2005.VideoAttributesType();
AspectRatioType aspectRatioType = new AspectRatioType();
aspectRatioType.setValue("16:9");
videoAttributesType.getAspectRatio().add(aspectRatioType);
avAttributesType.setVideoAttributes(videoAttributesType);        
prgInfo1.setAVAttributes(avAttributesType);

Put those objects in the ProgramInformaiton, ProgramInformationTable, & ProgramDescription objects:

prgInfoTable.getProgramInformation().add(prgInfo);
prgInfoTable.getProgramInformation().add(prgInfo1);
prgDesc.setProgramInformationTable(prgInfoTable);
mainType.setProgramDescription(prgDesc);

Create a client and submit the data and recieve the response:

MetasoftTVAServicePortTypeImpl metasoftClient = new MetasoftTVAServicePortTypeImpl();
Response response = metasoftClient.submitData(mainType);
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.3 Build:#641 Jan 13, 2007) - Bug/feature request - Contact Administrators