public ODataEntity getComputerDetailsEntity( final int id, final String sampleName, final boolean withInlineInfo, final String purchaseDate, String dimensionValue) { final ODataEntity entity = ODataObjectFactory.newEntity( "Microsoft.Test.OData.Services.AstoriaDefaultService.ComputerDetail"); entity.addProperty( ODataObjectFactory.newPrimitiveProperty( "Manufacturer", client .getPrimitiveValueBuilder() .setText("manufacturer name") .setType(EdmSimpleType.String) .build())); entity.addProperty( ODataObjectFactory.newPrimitiveProperty( "ComputerDetailId", client .getPrimitiveValueBuilder() .setText(String.valueOf(id)) .setType(EdmSimpleType.Int32) .build())); entity.addProperty( ODataObjectFactory.newPrimitiveProperty( "Model", client .getPrimitiveValueBuilder() .setText("Model Name") .setType(EdmSimpleType.String) .build())); entity.addProperty( ODataObjectFactory.newPrimitiveProperty( "PurchaseDate", client .getPrimitiveValueBuilder() .setText(purchaseDate) .setType(EdmSimpleType.DateTime) .build())); // add Dimensions attribute (collection) final ODataComplexValue dimensions = new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.Dimensions"); dimensions.add( ODataObjectFactory.newPrimitiveProperty( "Width", client .getPrimitiveValueBuilder() .setText(dimensionValue) .setType(EdmSimpleType.Decimal) .build())); dimensions.add( ODataObjectFactory.newPrimitiveProperty( "Height", client .getPrimitiveValueBuilder() .setText(dimensionValue) .setType(EdmSimpleType.Decimal) .build())); dimensions.add( ODataObjectFactory.newPrimitiveProperty( "Depth", client .getPrimitiveValueBuilder() .setText(dimensionValue) .setType(EdmSimpleType.Decimal) .build())); entity.addProperty(ODataObjectFactory.newComplexProperty("Dimensions", dimensions)); return entity; }
public ODataEntity getNewCustomer(final int id, final String name, final boolean withInlineInfo) { final ODataEntity entity = ODataObjectFactory.newEntity( "Microsoft.Test.OData.Services.AstoriaDefaultService.Customer"); // add name attribute entity.addProperty( ODataObjectFactory.newPrimitiveProperty( "Name", client.getPrimitiveValueBuilder().setText(name).setType(EdmSimpleType.String).build())); // add key attribute if (id != 0) { entity.addProperty( ODataObjectFactory.newPrimitiveProperty( "CustomerId", client .getPrimitiveValueBuilder() .setText(String.valueOf(id)) .setType(EdmSimpleType.Int32) .build())); } else { entity.addProperty( ODataObjectFactory.newPrimitiveProperty( "CustomerId", client .getPrimitiveValueBuilder() .setText(String.valueOf(0)) .setType(EdmSimpleType.Int32) .build())); } final ODataCollectionValue backupContactInfoValue = new ODataCollectionValue( "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)"); final ODataComplexValue contactDetails = new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails"); final ODataCollectionValue altNamesValue = new ODataCollectionValue("Collection(Edm.String)"); altNamesValue.add( client .getPrimitiveValueBuilder() .setText("My Alternative name") .setType(EdmSimpleType.String) .build()); contactDetails.add(ODataObjectFactory.newCollectionProperty("AlternativeNames", altNamesValue)); final ODataCollectionValue emailBagValue = new ODataCollectionValue("Collection(Edm.String)"); emailBagValue.add( client .getPrimitiveValueBuilder() .setText("*****@*****.**") .setType(EdmSimpleType.String) .build()); contactDetails.add(ODataObjectFactory.newCollectionProperty("EmailBag", emailBagValue)); final ODataComplexValue contactAliasValue = new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases"); contactDetails.add(ODataObjectFactory.newComplexProperty("ContactAlias", contactAliasValue)); final ODataCollectionValue aliasAltNamesValue = new ODataCollectionValue("Collection(Edm.String)"); aliasAltNamesValue.add( client .getPrimitiveValueBuilder() .setText("myAlternativeName") .setType(EdmSimpleType.String) .build()); contactAliasValue.add( ODataObjectFactory.newCollectionProperty("AlternativeNames", aliasAltNamesValue)); final ODataComplexValue homePhone = new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.Phone"); homePhone.add( ODataObjectFactory.newPrimitiveProperty( "PhoneNumber", client .getPrimitiveValueBuilder() .setText("8437568356834568") .setType(EdmSimpleType.String) .build())); homePhone.add( ODataObjectFactory.newPrimitiveProperty( "Extension", client .getPrimitiveValueBuilder() .setText("124365426534621534423ttrf") .setType(EdmSimpleType.String) .build())); contactDetails.add(ODataObjectFactory.newComplexProperty("HomePhone", homePhone)); backupContactInfoValue.add(contactDetails); entity.addProperty( ODataObjectFactory.newCollectionProperty("BackupContactInfo", backupContactInfoValue)); if (withInlineInfo) { final ODataInlineEntity inlineInfo = ODataObjectFactory.newInlineEntity( "Info", URI.create("Customer(" + id + ")/Info"), getInfo(id, name + "_Info")); inlineInfo.getEntity().setMediaEntity(true); entity.addLink(inlineInfo); } return entity; }