[OLINGO-200] Introducing interfaces for domain object

This commit is contained in:
Francesco Chicchiriccò 2014-03-29 14:48:17 +01:00
parent e0d1b6ffac
commit ceda474058
29 changed files with 1234 additions and 726 deletions

View File

@ -26,7 +26,6 @@ import org.apache.olingo.client.api.communication.request.retrieve.CommonRetriev
import org.apache.olingo.client.api.communication.request.streamed.CommonStreamedRequestFactory; import org.apache.olingo.client.api.communication.request.streamed.CommonStreamedRequestFactory;
import org.apache.olingo.client.api.op.ClientODataDeserializer; import org.apache.olingo.client.api.op.ClientODataDeserializer;
import org.apache.olingo.commons.api.domain.ODataObjectFactory; import org.apache.olingo.commons.api.domain.ODataObjectFactory;
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
import org.apache.olingo.client.api.op.CommonODataBinder; import org.apache.olingo.client.api.op.CommonODataBinder;
import org.apache.olingo.client.api.op.CommonODataReader; import org.apache.olingo.client.api.op.CommonODataReader;
import org.apache.olingo.commons.api.op.ODataSerializer; import org.apache.olingo.commons.api.op.ODataSerializer;
@ -47,8 +46,6 @@ public interface CommonODataClient {
CommonFilterFactory getFilterFactory(); CommonFilterFactory getFilterFactory();
ODataPrimitiveValue.Builder getPrimitiveValueBuilder();
ODataSerializer getSerializer(); ODataSerializer getSerializer();
ClientODataDeserializer getDeserializer(); ClientODataDeserializer getDeserializer();

View File

@ -21,8 +21,7 @@ package org.apache.olingo.client.core;
import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.commons.api.domain.ODataObjectFactory; import org.apache.olingo.commons.api.domain.ODataObjectFactory;
import org.apache.olingo.client.api.op.ODataWriter; import org.apache.olingo.client.api.op.ODataWriter;
import org.apache.olingo.commons.core.domain.ODataPrimitiveValueImpl; import org.apache.olingo.commons.core.domain.ODataObjectFactoryImpl;
import org.apache.olingo.commons.core.op.ODataObjectFactoryImpl;
import org.apache.olingo.client.core.op.ODataWriterImpl; import org.apache.olingo.client.core.op.ODataWriterImpl;
public abstract class AbstractODataClient implements CommonODataClient { public abstract class AbstractODataClient implements CommonODataClient {
@ -33,11 +32,6 @@ public abstract class AbstractODataClient implements CommonODataClient {
private final ODataObjectFactory objectFactory = new ODataObjectFactoryImpl(getServiceVersion()); private final ODataObjectFactory objectFactory = new ODataObjectFactoryImpl(getServiceVersion());
@Override
public ODataPrimitiveValueImpl.BuilderImpl getPrimitiveValueBuilder() {
return new ODataPrimitiveValueImpl.BuilderImpl(this.getServiceVersion());
}
@Override @Override
public ODataWriter getWriter() { public ODataWriter getWriter() {
return writer; return writer;

View File

@ -42,6 +42,7 @@ import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
import org.apache.olingo.commons.api.domain.ODataLink; import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.ODataOperation; import org.apache.olingo.commons.api.domain.ODataOperation;
import org.apache.olingo.commons.api.domain.ODataProperty; import org.apache.olingo.commons.api.domain.ODataProperty;
import org.apache.olingo.commons.core.domain.ODataPropertyImpl;
import org.apache.olingo.commons.api.domain.ODataServiceDocument; import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.domain.ODataValue; import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
@ -220,9 +221,9 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
if (property.hasPrimitiveValue()) { if (property.hasPrimitiveValue()) {
propertyResource.setType(property.getPrimitiveValue().getType().toString()); propertyResource.setType(property.getPrimitiveValue().getType().toString());
} else if (property.hasComplexValue()) { } else if (property.hasComplexValue()) {
propertyResource.setType(property.getComplexValue().getType()); propertyResource.setType(property.getComplexValue().getTypeName());
} else if (property.hasCollectionValue()) { } else if (property.hasCollectionValue()) {
propertyResource.setType(property.getCollectionValue().getType()); propertyResource.setType(property.getCollectionValue().getTypeName());
} }
} }
@ -284,7 +285,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
} }
for (Entry entryResource : resource.getEntries()) { for (Entry entryResource : resource.getEntries()) {
entitySet.addEntity(getODataEntity(entryResource)); entitySet.getEntities().add(getODataEntity(entryResource));
} }
return entitySet; return entitySet;
@ -369,20 +370,20 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
@Override @Override
public ODataProperty getODataProperty(final Property property) { public ODataProperty getODataProperty(final Property property) {
return new ODataProperty(property.getName(), getODataValue(property)); return new ODataPropertyImpl(property.getName(), getODataValue(property));
} }
private ODataValue getODataValue(final Property resource) { private ODataValue getODataValue(final Property resource) {
ODataValue value = null; ODataValue value = null;
if (resource.getValue().isPrimitive()) { if (resource.getValue().isPrimitive()) {
value = client.getPrimitiveValueBuilder(). value = client.getObjectFactory().newPrimitiveValueBuilder().
setText(resource.getValue().asPrimitive().get()). setText(resource.getValue().asPrimitive().get()).
setType(resource.getType() == null setType(resource.getType() == null
? null ? null
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build(); : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build();
} else if (resource.getValue().isGeospatial()) { } else if (resource.getValue().isGeospatial()) {
value = client.getPrimitiveValueBuilder(). value = client.getObjectFactory().newPrimitiveValueBuilder().
setValue(resource.getValue().asGeospatial().get()). setValue(resource.getValue().asGeospatial().get()).
setType(resource.getType() == null setType(resource.getType() == null
|| EdmPrimitiveTypeKind.Geography.getFullQualifiedName().toString().equals(resource.getType()) || EdmPrimitiveTypeKind.Geography.getFullQualifiedName().toString().equals(resource.getType())
@ -390,13 +391,13 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
? resource.getValue().asGeospatial().get().getEdmPrimitiveTypeKind() ? resource.getValue().asGeospatial().get().getEdmPrimitiveTypeKind()
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build(); : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build();
} else if (resource.getValue().isComplex()) { } else if (resource.getValue().isComplex()) {
value = new ODataComplexValue(resource.getType()); value = client.getObjectFactory().newComplexValue(resource.getType());
for (Property property : resource.getValue().asComplex().get()) { for (Property property : resource.getValue().asComplex().get()) {
value.asComplex().add(getODataProperty(property)); value.asComplex().add(getODataProperty(property));
} }
} else if (resource.getValue().isCollection()) { } else if (resource.getValue().isCollection()) {
value = new ODataCollectionValue(resource.getType()); value = client.getObjectFactory().newCollectionValue(resource.getType());
for (Value _value : resource.getValue().asCollection().get()) { for (Value _value : resource.getValue().asCollection().get()) {
final JSONPropertyImpl fake = new JSONPropertyImpl(); final JSONPropertyImpl fake = new JSONPropertyImpl();

View File

@ -126,7 +126,7 @@ public abstract class AbstractODataReader implements CommonODataReader {
container.getMetadataETag(), container.getMetadataETag(),
(T) client.getBinder().getODataProperty(container.getObject())); (T) client.getBinder().getODataProperty(container.getObject()));
} else if (ODataValue.class.isAssignableFrom(reference)) { } else if (ODataValue.class.isAssignableFrom(reference)) {
res = new Container<T>(null, null, (T) client.getPrimitiveValueBuilder(). res = new Container<T>(null, null, (T) client.getObjectFactory().newPrimitiveValueBuilder().
setType(ODataValueFormat.fromString(format) == ODataValueFormat.TEXT setType(ODataValueFormat.fromString(format) == ODataValueFormat.TEXT
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream). ? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
setText(IOUtils.toString(src)). setText(IOUtils.toString(src)).

View File

@ -213,7 +213,7 @@ public abstract class AbstractTestITCase {
entity.setMediaEntity(true); entity.setMediaEntity(true);
entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Information", entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Information",
getClient().getPrimitiveValueBuilder().setText(sampleinfo).setType( getClient().getObjectFactory().newPrimitiveValueBuilder().setText(sampleinfo).setType(
EdmPrimitiveTypeKind.String).build())); EdmPrimitiveTypeKind.String).build()));
return entity; return entity;
@ -227,45 +227,48 @@ public abstract class AbstractTestITCase {
// add name attribute // add name attribute
entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Name", entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Name",
getClient().getPrimitiveValueBuilder().setText(sampleName).setType( getClient().getObjectFactory().newPrimitiveValueBuilder().setText(sampleName).setType(
EdmPrimitiveTypeKind.String).build())); EdmPrimitiveTypeKind.String).build()));
// add key attribute // add key attribute
entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("CustomerId", entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("CustomerId",
getClient().getPrimitiveValueBuilder().setText(String.valueOf(id)).setType( getClient().getObjectFactory().newPrimitiveValueBuilder().setText(String.valueOf(id)).setType(
EdmPrimitiveTypeKind.Int32).build())); EdmPrimitiveTypeKind.Int32).build()));
// add BackupContactInfo attribute (collection) // add BackupContactInfo attribute (collection)
final ODataCollectionValue backupContactInfoValue = new ODataCollectionValue( final ODataCollectionValue backupContactInfoValue = getClient().getObjectFactory().newCollectionValue(
"Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)"); "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");
entity.getProperties().add(getClient().getObjectFactory().newCollectionProperty("BackupContactInfo", entity.getProperties().add(getClient().getObjectFactory().newCollectionProperty("BackupContactInfo",
backupContactInfoValue)); backupContactInfoValue));
// add BackupContactInfo.ContactDetails attribute (complex) // add BackupContactInfo.ContactDetails attribute (complex)
final ODataComplexValue contactDetails = new ODataComplexValue( final ODataComplexValue contactDetails = getClient().getObjectFactory().newComplexValue(
"Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails"); "Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
backupContactInfoValue.add(contactDetails); backupContactInfoValue.add(contactDetails);
// add BackupContactInfo.ContactDetails.AlternativeNames attribute (collection) // add BackupContactInfo.ContactDetails.AlternativeNames attribute (collection)
final ODataCollectionValue altNamesValue = new ODataCollectionValue("Collection(Edm.String)"); final ODataCollectionValue altNamesValue = getClient().getObjectFactory().
altNamesValue.add(getClient().getPrimitiveValueBuilder(). newCollectionValue("Collection(Edm.String)");
altNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
setText("myname").setType(EdmPrimitiveTypeKind.String).build()); setText("myname").setType(EdmPrimitiveTypeKind.String).build());
contactDetails.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue)); contactDetails.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue));
// add BackupContactInfo.ContactDetails.EmailBag attribute (collection) // add BackupContactInfo.ContactDetails.EmailBag attribute (collection)
final ODataCollectionValue emailBagValue = new ODataCollectionValue("Collection(Edm.String)"); final ODataCollectionValue emailBagValue = getClient().getObjectFactory().
emailBagValue.add(getClient().getPrimitiveValueBuilder(). newCollectionValue("Collection(Edm.String)");
emailBagValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
setText("myname@mydomain.com").setType(EdmPrimitiveTypeKind.String).build()); setText("myname@mydomain.com").setType(EdmPrimitiveTypeKind.String).build());
contactDetails.add(getClient().getObjectFactory().newCollectionProperty("EmailBag", emailBagValue)); contactDetails.add(getClient().getObjectFactory().newCollectionProperty("EmailBag", emailBagValue));
// add BackupContactInfo.ContactDetails.ContactAlias attribute (complex) // add BackupContactInfo.ContactDetails.ContactAlias attribute (complex)
final ODataComplexValue contactAliasValue = new ODataComplexValue( final ODataComplexValue contactAliasValue = getClient().getObjectFactory().newComplexValue(
"Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases"); "Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
contactDetails.add(getClient().getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue)); contactDetails.add(getClient().getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue));
// add BackupContactInfo.ContactDetails.ContactAlias.AlternativeNames attribute (collection) // add BackupContactInfo.ContactDetails.ContactAlias.AlternativeNames attribute (collection)
final ODataCollectionValue aliasAltNamesValue = new ODataCollectionValue("Collection(Edm.String)"); final ODataCollectionValue aliasAltNamesValue = getClient().getObjectFactory().
aliasAltNamesValue.add(getClient().getPrimitiveValueBuilder(). newCollectionValue("Collection(Edm.String)");
aliasAltNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
setText("myAlternativeName").setType(EdmPrimitiveTypeKind.String).build()); setText("myAlternativeName").setType(EdmPrimitiveTypeKind.String).build());
contactAliasValue.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue)); contactAliasValue.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue));
@ -511,7 +514,7 @@ public abstract class AbstractTestITCase {
assertNotEquals(newm, oldm); assertNotEquals(newm, oldm);
changes.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty(propertyName, changes.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty(propertyName,
getClient().getPrimitiveValueBuilder().setText(newm).build())); getClient().getObjectFactory().newPrimitiveValueBuilder().setText(newm).build()));
update(type, changes, format, etag); update(type, changes, format, etag);

View File

@ -75,7 +75,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
entity.getProperties().remove(entity.getProperty("Description")); entity.getProperties().remove(entity.getProperty("Description"));
entity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Description", entity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Description",
client.getPrimitiveValueBuilder().setText("AsyncTest#updateEntity").build())); client.getObjectFactory().newPrimitiveValueBuilder().setText("AsyncTest#updateEntity").build()));
final ODataEntityUpdateRequest updateReq = final ODataEntityUpdateRequest updateReq =
client.getCUDRequestFactory().getEntityUpdateRequest(uri, UpdateType.MERGE, entity); client.getCUDRequestFactory().getEntityUpdateRequest(uri, UpdateType.MERGE, entity);

View File

@ -291,10 +291,10 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Order"); client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Order");
order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("OrderId", order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("OrderId",
client.getPrimitiveValueBuilder().setValue(key).setType(EdmPrimitiveTypeKind.Int32) client.getObjectFactory().newPrimitiveValueBuilder().setValue(key).setType(EdmPrimitiveTypeKind.Int32)
.build())); .build()));
order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId", order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId",
client.getPrimitiveValueBuilder().setValue(id).setType(EdmPrimitiveTypeKind.Int32) client.getObjectFactory().newPrimitiveValueBuilder().setValue(id).setType(EdmPrimitiveTypeKind.Int32)
.build())); .build()));
final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest( final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest(
@ -388,9 +388,11 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
ODataEntity order = client.getObjectFactory().newEntity( ODataEntity order = client.getObjectFactory().newEntity(
"Microsoft.Test.OData.Services.AstoriaDefaultService.Order"); "Microsoft.Test.OData.Services.AstoriaDefaultService.Order");
order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId", order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId",
client.getPrimitiveValueBuilder().setValue(id).setType(EdmPrimitiveTypeKind.Int32).build())); client.getObjectFactory().newPrimitiveValueBuilder().setValue(id).
setType(EdmPrimitiveTypeKind.Int32).build()));
order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("OrderId", order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("OrderId",
client.getPrimitiveValueBuilder().setValue(id).setType(EdmPrimitiveTypeKind.Int32).build())); client.getObjectFactory().newPrimitiveValueBuilder().setValue(id).
setType(EdmPrimitiveTypeKind.Int32).build()));
order.addLink(client.getObjectFactory().newEntityNavigationLink( order.addLink(client.getObjectFactory().newEntityNavigationLink(
"Customer", URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString()))); "Customer", URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString())));
@ -446,22 +448,22 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
"Microsoft.Test.OData.Services.AstoriaDefaultService.Message"); "Microsoft.Test.OData.Services.AstoriaDefaultService.Message");
message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("MessageId", message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("MessageId",
client.getPrimitiveValueBuilder().setValue(1000). client.getObjectFactory().newPrimitiveValueBuilder().setValue(1000).
setType(EdmPrimitiveTypeKind.Int32).build())); setType(EdmPrimitiveTypeKind.Int32).build()));
message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("FromUsername", message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("FromUsername",
client.getPrimitiveValueBuilder().setValue("1"). client.getObjectFactory().newPrimitiveValueBuilder().setValue("1").
setType(EdmPrimitiveTypeKind.String).build())); setType(EdmPrimitiveTypeKind.String).build()));
message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("ToUsername", message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("ToUsername",
client.getPrimitiveValueBuilder().setValue("xlodhxzzusxecbzptxlfxprneoxkn"). client.getObjectFactory().newPrimitiveValueBuilder().setValue("xlodhxzzusxecbzptxlfxprneoxkn").
setType(EdmPrimitiveTypeKind.String).build())); setType(EdmPrimitiveTypeKind.String).build()));
message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Subject", message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Subject",
client.getPrimitiveValueBuilder().setValue("Test subject"). client.getObjectFactory().newPrimitiveValueBuilder().setValue("Test subject").
setType(EdmPrimitiveTypeKind.String).build())); setType(EdmPrimitiveTypeKind.String).build()));
message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Body", message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Body",
client.getPrimitiveValueBuilder().setValue("Test body"). client.getObjectFactory().newPrimitiveValueBuilder().setValue("Test body").
setType(EdmPrimitiveTypeKind.String).build())); setType(EdmPrimitiveTypeKind.String).build()));
message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("IsRead", message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("IsRead",
client.getPrimitiveValueBuilder().setValue(false). client.getObjectFactory().newPrimitiveValueBuilder().setValue(false).
setType(EdmPrimitiveTypeKind.Boolean).build())); setType(EdmPrimitiveTypeKind.Boolean).build()));
final CommonURIBuilder<?> builder = final CommonURIBuilder<?> builder =

View File

@ -186,7 +186,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
final boolean before = message.getProperty("IsRead").getPrimitiveValue().toCastValue(Boolean.class); final boolean before = message.getProperty("IsRead").getPrimitiveValue().toCastValue(Boolean.class);
message.getProperties().remove(message.getProperty("IsRead")); message.getProperties().remove(message.getProperty("IsRead"));
message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("IsRead", message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("IsRead",
client.getPrimitiveValueBuilder().setValue(!before). client.getObjectFactory().newPrimitiveValueBuilder().setValue(!before).
setType(EdmPrimitiveTypeKind.Boolean).build())); setType(EdmPrimitiveTypeKind.Boolean).build()));
return client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.MERGE, message); return client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.MERGE, message);

View File

@ -210,9 +210,11 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Order"); client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Order");
orderEntity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("OrderId", orderEntity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("OrderId",
client.getPrimitiveValueBuilder().setValue(key).setType(EdmPrimitiveTypeKind.Int32).build())); client.getObjectFactory().newPrimitiveValueBuilder().setValue(key).
setType(EdmPrimitiveTypeKind.Int32).build()));
orderEntity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId", orderEntity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId",
client.getPrimitiveValueBuilder().setValue(id).setType(EdmPrimitiveTypeKind.Int32).build())); client.getObjectFactory().newPrimitiveValueBuilder().setValue(id).
setType(EdmPrimitiveTypeKind.Int32).build()));
final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest( final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest(
client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Order").build(), client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Order").build(),
@ -268,48 +270,50 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
// add name attribute // add name attribute
entity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Name", entity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Name",
client.getPrimitiveValueBuilder().setText(name).setType(EdmPrimitiveTypeKind.String).build())); client.getObjectFactory().newPrimitiveValueBuilder().setText(name).
setType(EdmPrimitiveTypeKind.String).build()));
// add key attribute // add key attribute
if (id != 0) { if (id != 0) {
entity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId", entity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId",
client.getPrimitiveValueBuilder().setText(String.valueOf(id)). client.getObjectFactory().newPrimitiveValueBuilder().setText(String.valueOf(id)).
setType(EdmPrimitiveTypeKind.Int32).build())); setType(EdmPrimitiveTypeKind.Int32).build()));
} }
final ODataCollectionValue backupContactInfoValue = new ODataCollectionValue( final ODataCollectionValue backupContactInfoValue = getClient().getObjectFactory().newCollectionValue(
"Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)"); "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");
final ODataComplexValue contactDetails = getClient().getObjectFactory().newComplexValue(
final ODataComplexValue contactDetails = new ODataComplexValue(
"Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails"); "Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
final ODataCollectionValue altNamesValue = getClient().getObjectFactory().
final ODataCollectionValue altNamesValue = new ODataCollectionValue("Collection(Edm.String)"); newCollectionValue("Collection(Edm.String)");
altNamesValue.add(client.getPrimitiveValueBuilder(). altNamesValue.add(client.getObjectFactory().newPrimitiveValueBuilder().
setText("My Alternative name").setType(EdmPrimitiveTypeKind.String).build()); setText("My Alternative name").setType(EdmPrimitiveTypeKind.String).build());
contactDetails.add(client.getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue)); contactDetails.add(client.getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue));
final ODataCollectionValue emailBagValue = new ODataCollectionValue("Collection(Edm.String)"); final ODataCollectionValue emailBagValue = getClient().getObjectFactory().
emailBagValue.add(client.getPrimitiveValueBuilder(). newCollectionValue("Collection(Edm.String)");
emailBagValue.add(client.getObjectFactory().newPrimitiveValueBuilder().
setText("altname@mydomain.com").setType(EdmPrimitiveTypeKind.String).build()); setText("altname@mydomain.com").setType(EdmPrimitiveTypeKind.String).build());
contactDetails.add(client.getObjectFactory().newCollectionProperty("EmailBag", emailBagValue)); contactDetails.add(client.getObjectFactory().newCollectionProperty("EmailBag", emailBagValue));
final ODataComplexValue contactAliasValue = new ODataComplexValue( final ODataComplexValue contactAliasValue = getClient().getObjectFactory().newComplexValue(
"Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases"); "Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
contactDetails.add(client.getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue)); contactDetails.add(client.getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue));
final ODataCollectionValue aliasAltNamesValue = new ODataCollectionValue("Collection(Edm.String)"); final ODataCollectionValue aliasAltNamesValue = getClient().getObjectFactory().
aliasAltNamesValue.add(client.getPrimitiveValueBuilder(). newCollectionValue("Collection(Edm.String)");
aliasAltNamesValue.add(client.getObjectFactory().newPrimitiveValueBuilder().
setText("myAlternativeName").setType(EdmPrimitiveTypeKind.String).build()); setText("myAlternativeName").setType(EdmPrimitiveTypeKind.String).build());
contactAliasValue.add(client.getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue)); contactAliasValue.add(client.getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue));
final ODataComplexValue homePhone = new ODataComplexValue( final ODataComplexValue homePhone = getClient().getObjectFactory().newComplexValue(
"Microsoft.Test.OData.Services.AstoriaDefaultService.Phone"); "Microsoft.Test.OData.Services.AstoriaDefaultService.Phone");
homePhone.add(client.getObjectFactory().newPrimitiveProperty("PhoneNumber", homePhone.add(client.getObjectFactory().newPrimitiveProperty("PhoneNumber",
client.getPrimitiveValueBuilder().setText("8437568356834568"). client.getObjectFactory().newPrimitiveValueBuilder().setText("8437568356834568").
setType(EdmPrimitiveTypeKind.String).build())); setType(EdmPrimitiveTypeKind.String).build()));
homePhone.add(client.getObjectFactory().newPrimitiveProperty("Extension", homePhone.add(client.getObjectFactory().newPrimitiveProperty("Extension",
client.getPrimitiveValueBuilder().setText("124365426534621534423ttrf"). client.getObjectFactory().newPrimitiveValueBuilder().setText("124365426534621534423ttrf").
setType(EdmPrimitiveTypeKind.String). setType(EdmPrimitiveTypeKind.String).
build())); build()));
contactDetails.add(client.getObjectFactory().newComplexProperty("HomePhone", homePhone)); contactDetails.add(client.getObjectFactory().newComplexProperty("HomePhone", homePhone));
@ -373,7 +377,8 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
entity.setMediaEntity(true); entity.setMediaEntity(true);
entity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Information", entity.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Information",
client.getPrimitiveValueBuilder().setText(info).setType(EdmPrimitiveTypeKind.String).build())); client.getObjectFactory().newPrimitiveValueBuilder().setText(info).
setType(EdmPrimitiveTypeKind.String).build()));
return entity; return entity;
} }
// validate newly created entities // validate newly created entities

View File

@ -93,50 +93,57 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
ODataEntity row = client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.OpenTypesService.Row"); ODataEntity row = client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.OpenTypesService.Row");
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Id", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Id",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Guid).setValue(guid). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Guid).setValue(guid).
build())); build()));
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aString", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aString",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.String).setValue("string"). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.String).setValue("string").
build())); build()));
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aBoolean", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aBoolean",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Boolean).setValue(true). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Boolean).setValue(true).
build())); build()));
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aLong", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aLong",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Int64).setValue(15L). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Int64).setValue(15L).
build())); build()));
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aDouble", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aDouble",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Double).setValue(1.5D). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Double).setValue(1.5D).
build())); build()));
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aByte", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aByte",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).
build())); build()));
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aDate", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aDate",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.DateTime).setValue(new Date()). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.DateTime).setValue(new Date()).
build())); build()));
final Point point = new Point(Geospatial.Dimension.GEOGRAPHY, null); final Point point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(1.2); point.setX(1.2);
point.setY(2.1); point.setY(2.1);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aPoint", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aPoint",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPoint). client.getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPoint).
setValue(point).build())); setValue(point).build()));
final List<Point> points = new ArrayList<Point>(); final List<Point> points = new ArrayList<Point>();
points.add(point); points.add(point);
points.add(point); points.add(point);
final MultiPoint multipoint = new MultiPoint(Geospatial.Dimension.GEOMETRY, null, points); final MultiPoint multipoint = new MultiPoint(Geospatial.Dimension.GEOMETRY, null, points);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiPoint", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiPoint",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiPoint). client.getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiPoint).
setValue(multipoint).build())); setValue(multipoint).build()));
final LineString lineString = new LineString(Geospatial.Dimension.GEOMETRY, null, points); final LineString lineString = new LineString(Geospatial.Dimension.GEOMETRY, null, points);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aLineString", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aLineString",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryLineString). client.getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryLineString).
setValue(lineString).build())); setValue(lineString).build()));
final List<LineString> lineStrings = new ArrayList<LineString>(); final List<LineString> lineStrings = new ArrayList<LineString>();
lineStrings.add(lineString); lineStrings.add(lineString);
lineStrings.add(lineString); lineStrings.add(lineString);
final MultiLineString multiLineString = new MultiLineString(Geospatial.Dimension.GEOGRAPHY, null, lineStrings); final MultiLineString multiLineString = new MultiLineString(Geospatial.Dimension.GEOGRAPHY, null, lineStrings);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiLineString", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiLineString",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiLineString). client.getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiLineString).
setValue(multiLineString).build())); setValue(multiLineString).build()));
final Point otherPoint = new Point(Geospatial.Dimension.GEOGRAPHY, null); final Point otherPoint = new Point(Geospatial.Dimension.GEOGRAPHY, null);
otherPoint.setX(3.4); otherPoint.setX(3.4);
@ -146,14 +153,14 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
points.add(point); points.add(point);
final Polygon polygon = new Polygon(Geospatial.Dimension.GEOGRAPHY, null, points, points); final Polygon polygon = new Polygon(Geospatial.Dimension.GEOGRAPHY, null, points, points);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aPolygon", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aPolygon",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPolygon). client.getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPolygon).
setValue(polygon).build())); setValue(polygon).build()));
final List<Polygon> polygons = new ArrayList<Polygon>(); final List<Polygon> polygons = new ArrayList<Polygon>();
polygons.add(polygon); polygons.add(polygon);
polygons.add(polygon); polygons.add(polygon);
final MultiPolygon multiPolygon = new MultiPolygon(Geospatial.Dimension.GEOGRAPHY, null, polygons); final MultiPolygon multiPolygon = new MultiPolygon(Geospatial.Dimension.GEOGRAPHY, null, polygons);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiPolygon", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiPolygon",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyMultiPolygon). client.getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyMultiPolygon).
setValue(multiPolygon).build())); setValue(multiPolygon).build()));
final List<Geospatial> geospatials = new ArrayList<Geospatial>(); final List<Geospatial> geospatials = new ArrayList<Geospatial>();
geospatials.add(otherPoint); geospatials.add(otherPoint);
@ -162,46 +169,46 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
geospatials.add(multiPolygon); geospatials.add(multiPolygon);
final GeospatialCollection geoColl = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, null, geospatials); final GeospatialCollection geoColl = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, null, geospatials);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aCollection", row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aCollection",
client.getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyCollection). client.getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyCollection).
setValue(geoColl).build())); setValue(geoColl).build()));
final ODataComplexValue contactDetails = final ODataComplexValue contactDetails = client.getObjectFactory().newComplexValue(
new ODataComplexValue("Microsoft.Test.OData.Services.OpenTypesService.ContactDetails"); "Microsoft.Test.OData.Services.OpenTypesService.ContactDetails");
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("FirstContacted", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("FirstContacted",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Binary).setValue("text".getBytes()).build())); setType(EdmPrimitiveTypeKind.Binary).setValue("text".getBytes()).build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("LastContacted", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("LastContacted",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2001-04-05T05:05:05.001+00:01").build())); setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2001-04-05T05:05:05.001+00:01").build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Contacted", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Contacted",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.DateTime).setText("2001-04-05T05:05:04.001").build())); setType(EdmPrimitiveTypeKind.DateTime).setText("2001-04-05T05:05:04.001").build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("GUID", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("GUID",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Guid).setValue(UUID.randomUUID()).build())); setType(EdmPrimitiveTypeKind.Guid).setValue(UUID.randomUUID()).build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("PreferedContactTime", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("PreferedContactTime",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Time).setText("-P9DT51M10.5063807S").build())); setType(EdmPrimitiveTypeKind.Time).setText("-P9DT51M10.5063807S").build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Byte", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Byte",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Byte).setValue(Integer.valueOf(241)).build())); setType(EdmPrimitiveTypeKind.Byte).setValue(Integer.valueOf(241)).build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("SignedByte", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("SignedByte",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).build())); setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Double", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Double",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Double).setValue(Double.MAX_VALUE).build())); setType(EdmPrimitiveTypeKind.Double).setValue(Double.MAX_VALUE).build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Single", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Single",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Single).setValue(Float.MAX_VALUE).build())); setType(EdmPrimitiveTypeKind.Single).setValue(Float.MAX_VALUE).build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Short", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Short",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Int16).setValue(Short.MAX_VALUE).build())); setType(EdmPrimitiveTypeKind.Int16).setValue(Short.MAX_VALUE).build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Int", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Int",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Int32).setValue(Integer.MAX_VALUE).build())); setType(EdmPrimitiveTypeKind.Int32).setValue(Integer.MAX_VALUE).build()));
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Long", contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Long",
client.getPrimitiveValueBuilder(). client.getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Int64).setValue(Long.MAX_VALUE).build())); setType(EdmPrimitiveTypeKind.Int64).setValue(Long.MAX_VALUE).build()));
row.getProperties().add(client.getObjectFactory().newComplexProperty("aContact", contactDetails)); row.getProperties().add(client.getObjectFactory().newComplexProperty("aContact", contactDetails));
@ -243,7 +250,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
assertEquals(EdmPrimitiveTypeKind.GeographyCollection, assertEquals(EdmPrimitiveTypeKind.GeographyCollection,
row.getProperty("aCollection").getPrimitiveValue().getTypeKind()); row.getProperty("aCollection").getPrimitiveValue().getTypeKind());
assertEquals("Microsoft.Test.OData.Services.OpenTypesService.ContactDetails", assertEquals("Microsoft.Test.OData.Services.OpenTypesService.ContactDetails",
row.getProperty("aContact").getComplexValue().getType()); row.getProperty("aContact").getComplexValue().getTypeName());
assertEquals(EdmPrimitiveTypeKind.SByte, assertEquals(EdmPrimitiveTypeKind.SByte,
row.getProperty("aContact").getComplexValue().get("SignedByte").getPrimitiveValue().getTypeKind()); row.getProperty("aContact").getComplexValue().get("SignedByte").getPrimitiveValue().getTypeKind());

View File

@ -181,7 +181,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
assertNotEquals(newMsg, oldMsg); assertNotEquals(newMsg, oldMsg);
final ODataPrimitiveValue newVal = client.getPrimitiveValueBuilder().setText(newMsg).build(); final ODataPrimitiveValue newVal = client.getObjectFactory().newPrimitiveValueBuilder().setText(newMsg).build();
final ODataValueUpdateRequest updateReq = final ODataValueUpdateRequest updateReq =
client.getCUDRequestFactory().getValueUpdateRequest(uriBuilder.build(), type, newVal); client.getCUDRequestFactory().getValueUpdateRequest(uriBuilder.build(), type, newVal);
@ -222,7 +222,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
final int origSize = originalValue.size(); final int origSize = originalValue.size();
originalValue.add(client.getPrimitiveValueBuilder().setText(newItem).build()); originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setText(newItem).build());
assertEquals(origSize + 1, originalValue.size()); assertEquals(origSize + 1, originalValue.size());
final ODataPropertyUpdateRequest updateReq = client.getCUDRequestFactory(). final ODataPropertyUpdateRequest updateReq = client.getCUDRequestFactory().
@ -268,7 +268,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
final int origSize = originalValue.size(); final int origSize = originalValue.size();
originalValue.add(client.getPrimitiveValueBuilder().setText(newItem).build()); originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setText(newItem).build());
assertEquals(origSize + 1, originalValue.size()); assertEquals(origSize + 1, originalValue.size());
final ODataPropertyUpdateRequest updateReq = final ODataPropertyUpdateRequest updateReq =
@ -315,7 +315,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
assertNotEquals(newMsg, oldMsg); assertNotEquals(newMsg, oldMsg);
phoneNumber = client.getObjectFactory().newPrimitiveProperty("PhoneNumber", phoneNumber = client.getObjectFactory().newPrimitiveProperty("PhoneNumber",
client.getPrimitiveValueBuilder().setText(newMsg).build()); client.getObjectFactory().newPrimitiveValueBuilder().setText(newMsg).build());
final ODataPropertyUpdateRequest updateReq = final ODataPropertyUpdateRequest updateReq =
client.getCUDRequestFactory().getPropertyPrimitiveValueUpdateRequest(uriBuilder.build(), phoneNumber); client.getCUDRequestFactory().getPropertyPrimitiveValueUpdateRequest(uriBuilder.build(), phoneNumber);

View File

@ -57,24 +57,25 @@ public class PrimitiveValueTest extends AbstractTest {
@Test @Test
public void manageInt32() throws EdmPrimitiveTypeException { public void manageInt32() throws EdmPrimitiveTypeException {
final int primitive = -10; final int primitive = -10;
ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Int32). ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Int32).
setValue(primitive).build(); setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.Int32, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Int32, value.asPrimitive().getTypeKind());
assertEquals(Integer.valueOf(primitive), value.asPrimitive().toCastValue(Integer.class)); assertEquals(Integer.valueOf(primitive), value.asPrimitive().toCastValue(Integer.class));
value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Int32).setText("9").build(); value = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Int32).setText("9").build();
assertEquals("9", value.asPrimitive().toCastValue(Integer.class).toString()); assertEquals("9", value.asPrimitive().toCastValue(Integer.class).toString());
} }
@Test @Test
public void manageString() throws EdmPrimitiveTypeException { public void manageString() throws EdmPrimitiveTypeException {
final String primitive = UUID.randomUUID().toString(); final String primitive = UUID.randomUUID().toString();
ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.String). ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.String).
setText(primitive).build(); setText(primitive).build();
assertEquals(EdmPrimitiveTypeKind.String, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.String, value.asPrimitive().getTypeKind());
assertEquals(primitive, value.toString()); assertEquals(primitive, value.toString());
value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.String). value = getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.String).
setText("1126a28b-a4af-4bbd-bf0a-2b2c22635565").build(); setText("1126a28b-a4af-4bbd-bf0a-2b2c22635565").build();
assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().toCastValue(String.class).toString()); assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().toCastValue(String.class).toString());
} }
@ -82,12 +83,12 @@ public class PrimitiveValueTest extends AbstractTest {
@Test @Test
public void manageDecimal() throws EdmPrimitiveTypeException { public void manageDecimal() throws EdmPrimitiveTypeException {
final BigDecimal primitive = new BigDecimal("-79228162514264337593543950335"); final BigDecimal primitive = new BigDecimal("-79228162514264337593543950335");
ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Decimal). ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Decimal).
setValue(primitive).build(); setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.Decimal, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Decimal, value.asPrimitive().getTypeKind());
assertEquals(primitive, value.asPrimitive().toCastValue(BigDecimal.class)); assertEquals(primitive, value.asPrimitive().toCastValue(BigDecimal.class));
value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Decimal). value = getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Decimal).
setText("-79228162514264337593543950335").build(); setText("-79228162514264337593543950335").build();
assertEquals("-79228162514264337593543950335", value.asPrimitive().toCastValue(BigDecimal.class).toString()); assertEquals("-79228162514264337593543950335", value.asPrimitive().toCastValue(BigDecimal.class).toString());
} }
@ -99,7 +100,7 @@ public class PrimitiveValueTest extends AbstractTest {
expected.set(2013, 0, 10, 2, 0, 0); expected.set(2013, 0, 10, 2, 0, 0);
expected.set(Calendar.MILLISECOND, 1667673); expected.set(Calendar.MILLISECOND, 1667673);
final ODataValue value = getClient().getPrimitiveValueBuilder(). final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.DateTime).setValue(expected).build(); setType(EdmPrimitiveTypeKind.DateTime).setValue(expected).build();
assertEquals(EdmPrimitiveTypeKind.DateTime, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.DateTime, value.asPrimitive().getTypeKind());
@ -123,7 +124,7 @@ public class PrimitiveValueTest extends AbstractTest {
public void manageTime() throws EdmPrimitiveTypeException { public void manageTime() throws EdmPrimitiveTypeException {
final String primitive = "-P9DT51M10.5063807S"; final String primitive = "-P9DT51M10.5063807S";
final ODataValue value = final ODataValue value =
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Time). getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Time).
setText(primitive).build(); setText(primitive).build();
assertEquals(EdmPrimitiveTypeKind.Time, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Time, value.asPrimitive().getTypeKind());
// performed cast to improve the check // performed cast to improve the check
@ -137,7 +138,7 @@ public class PrimitiveValueTest extends AbstractTest {
expected.setTimeZone(TimeZone.getTimeZone("GMT")); expected.setTimeZone(TimeZone.getTimeZone("GMT"));
expected.set(2013, 0, 10, 2, 0, 0); expected.set(2013, 0, 10, 2, 0, 0);
final ODataValue value = getClient().getPrimitiveValueBuilder(). final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(expected).build(); setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(expected).build();
assertEquals(EdmPrimitiveTypeKind.DateTimeOffset, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.DateTimeOffset, value.asPrimitive().getTypeKind());
@ -155,12 +156,12 @@ public class PrimitiveValueTest extends AbstractTest {
@Test @Test
public void manageGuid() throws EdmPrimitiveTypeException { public void manageGuid() throws EdmPrimitiveTypeException {
final UUID primitive = UUID.fromString("1126a28b-a4af-4bbd-bf0a-2b2c22635565"); final UUID primitive = UUID.fromString("1126a28b-a4af-4bbd-bf0a-2b2c22635565");
ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Guid). ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Guid).
setValue(primitive).build(); setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.Guid, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Guid, value.asPrimitive().getTypeKind());
assertEquals(primitive, value.asPrimitive().toCastValue(UUID.class)); assertEquals(primitive, value.asPrimitive().toCastValue(UUID.class));
value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Guid). value = getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Guid).
setText("1126a28b-a4af-4bbd-bf0a-2b2c22635565").build(); setText("1126a28b-a4af-4bbd-bf0a-2b2c22635565").build();
assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().toCastValue(UUID.class).toString()); assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().toCastValue(UUID.class).toString());
} }
@ -168,14 +169,15 @@ public class PrimitiveValueTest extends AbstractTest {
@Test @Test
public void manageBinary() throws EdmPrimitiveTypeException { public void manageBinary() throws EdmPrimitiveTypeException {
final byte[] primitive = UUID.randomUUID().toString().getBytes(); final byte[] primitive = UUID.randomUUID().toString().getBytes();
ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Binary). ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Binary).
setValue(primitive).build(); setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.Binary, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Binary, value.asPrimitive().getTypeKind());
assertEquals( assertEquals(
Base64.encodeBase64String(primitive), Base64.encodeBase64String(primitive),
Base64.encodeBase64String(value.asPrimitive().toCastValue(byte[].class))); Base64.encodeBase64String(value.asPrimitive().toCastValue(byte[].class)));
value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Binary). value = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Binary).
setText(Base64.encodeBase64String("primitive".getBytes())).build(); setText(Base64.encodeBase64String("primitive".getBytes())).build();
assertEquals("primitive", new String(value.asPrimitive().toCastValue(byte[].class))); assertEquals("primitive", new String(value.asPrimitive().toCastValue(byte[].class)));
} }
@ -186,8 +188,8 @@ public class PrimitiveValueTest extends AbstractTest {
primitive.setX(52.8606); primitive.setX(52.8606);
primitive.setY(173.334); primitive.setY(173.334);
final ODataValue value = final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPoint). setType(EdmPrimitiveTypeKind.GeographyPoint).
setValue(primitive). setValue(primitive).
build(); build();
assertEquals(EdmPrimitiveTypeKind.GeographyPoint, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.GeographyPoint, value.asPrimitive().getTypeKind());
@ -222,8 +224,9 @@ public class PrimitiveValueTest extends AbstractTest {
final LineString primitive = new LineString(Geospatial.Dimension.GEOGRAPHY, null, points); final LineString primitive = new LineString(Geospatial.Dimension.GEOGRAPHY, null, points);
final ODataValue value = getClient().getPrimitiveValueBuilder(). final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.GeographyLineString).setValue(primitive).build(); setType(EdmPrimitiveTypeKind.GeographyLineString).
setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.GeographyLineString, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.GeographyLineString, value.asPrimitive().getTypeKind());
final Iterator<Point> iter = value.asPrimitive().toCastValue(LineString.class).iterator(); final Iterator<Point> iter = value.asPrimitive().toCastValue(LineString.class).iterator();
@ -247,8 +250,9 @@ public class PrimitiveValueTest extends AbstractTest {
final MultiPoint primitive = new MultiPoint(Geospatial.Dimension.GEOMETRY, null, points); final MultiPoint primitive = new MultiPoint(Geospatial.Dimension.GEOMETRY, null, points);
final ODataValue value = getClient().getPrimitiveValueBuilder(). final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.GeometryMultiPoint).setValue(primitive).build(); setType(EdmPrimitiveTypeKind.GeometryMultiPoint).
setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.GeometryMultiPoint, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.GeometryMultiPoint, value.asPrimitive().getTypeKind());
final Iterator<Point> iter = value.asPrimitive().toCastValue(MultiPoint.class).iterator(); final Iterator<Point> iter = value.asPrimitive().toCastValue(MultiPoint.class).iterator();
@ -307,8 +311,8 @@ public class PrimitiveValueTest extends AbstractTest {
final MultiLineString primitive = new MultiLineString(Geospatial.Dimension.GEOMETRY, null, lines); final MultiLineString primitive = new MultiLineString(Geospatial.Dimension.GEOMETRY, null, lines);
final ODataValue value = final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiLineString). setType(EdmPrimitiveTypeKind.GeometryMultiLineString).
setValue(primitive).build(); setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.GeometryMultiLineString, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.GeometryMultiLineString, value.asPrimitive().getTypeKind());
@ -360,8 +364,8 @@ public class PrimitiveValueTest extends AbstractTest {
final Polygon primitive = new Polygon(Geospatial.Dimension.GEOGRAPHY, null, interior, exterior); final Polygon primitive = new Polygon(Geospatial.Dimension.GEOGRAPHY, null, interior, exterior);
final ODataValue value = final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPolygon). setType(EdmPrimitiveTypeKind.GeographyPolygon).
setValue(primitive).build(); setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.GeographyPolygon, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.GeographyPolygon, value.asPrimitive().getTypeKind());
@ -466,8 +470,8 @@ public class PrimitiveValueTest extends AbstractTest {
final MultiPolygon primitive = new MultiPolygon(Geospatial.Dimension.GEOMETRY, null, polygons); final MultiPolygon primitive = new MultiPolygon(Geospatial.Dimension.GEOMETRY, null, polygons);
final ODataValue value = final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiPolygon). setType(EdmPrimitiveTypeKind.GeometryMultiPolygon).
setValue(primitive).build(); setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.GeometryMultiPolygon, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.GeometryMultiPolygon, value.asPrimitive().getTypeKind());
@ -512,8 +516,8 @@ public class PrimitiveValueTest extends AbstractTest {
final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOMETRY, null, collection); final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOMETRY, null, collection);
final ODataValue value = final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeometryCollection). setType(EdmPrimitiveTypeKind.GeometryCollection).
setValue(primitive).build(); setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.GeometryCollection, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.GeometryCollection, value.asPrimitive().getTypeKind());
@ -544,8 +548,8 @@ public class PrimitiveValueTest extends AbstractTest {
final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, null, collection); final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, null, collection);
final ODataValue value = final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.GeographyCollection). setType(EdmPrimitiveTypeKind.GeographyCollection).
setValue(primitive).build(); setValue(primitive).build();
assertEquals(EdmPrimitiveTypeKind.GeographyCollection, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.GeographyCollection, value.asPrimitive().getTypeKind());

View File

@ -49,7 +49,7 @@ public class PropertyTest extends AbstractTest {
public void readPropertyValue() throws IOException { public void readPropertyValue() throws IOException {
final InputStream input = getClass().getResourceAsStream("Customer_-10_CustomerId_value.txt"); final InputStream input = getClass().getResourceAsStream("Customer_-10_CustomerId_value.txt");
final ODataPrimitiveValue value = getClient().getPrimitiveValueBuilder(). final ODataPrimitiveValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.String). setType(EdmPrimitiveTypeKind.String).
setText(IOUtils.toString(input)). setText(IOUtils.toString(input)).
build(); build();
@ -71,7 +71,7 @@ public class PropertyTest extends AbstractTest {
comparable = written; comparable = written;
} else { } else {
// This is needed because type information gets lost with JSON serialization // This is needed because type information gets lost with JSON serialization
final ODataPrimitiveValue typedValue = getClient().getPrimitiveValueBuilder(). final ODataPrimitiveValue typedValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(property.getPrimitiveValue().getTypeKind()). setType(property.getPrimitiveValue().getTypeKind()).
setText(written.getPrimitiveValue().toString()). setText(written.getPrimitiveValue().toString()).
build(); build();
@ -107,7 +107,8 @@ public class PropertyTest extends AbstractTest {
comparable = written; comparable = written;
} else { } else {
// This is needed because type information gets lost with JSON serialization // This is needed because type information gets lost with JSON serialization
final ODataComplexValue typedValue = new ODataComplexValue(property.getComplexValue().getType()); final ODataComplexValue typedValue = getClient().getObjectFactory().
newComplexValue(property.getComplexValue().getTypeName());
for (final Iterator<ODataProperty> itor = written.getComplexValue().iterator(); itor.hasNext();) { for (final Iterator<ODataProperty> itor = written.getComplexValue().iterator(); itor.hasNext();) {
final ODataProperty prop = itor.next(); final ODataProperty prop = itor.next();
typedValue.add(prop); typedValue.add(prop);
@ -144,7 +145,8 @@ public class PropertyTest extends AbstractTest {
comparable = written; comparable = written;
} else { } else {
// This is needed because type information gets lost with JSON serialization // This is needed because type information gets lost with JSON serialization
final ODataCollectionValue typedValue = new ODataCollectionValue(property.getCollectionValue().getType()); final ODataCollectionValue typedValue = getClient().getObjectFactory().
newCollectionValue(property.getCollectionValue().getTypeName());
for (final Iterator<ODataValue> itor = written.getCollectionValue().iterator(); itor.hasNext();) { for (final Iterator<ODataValue> itor = written.getCollectionValue().iterator(); itor.hasNext();) {
final ODataValue value = itor.next(); final ODataValue value = itor.next();
typedValue.add(value); typedValue.add(value);

View File

@ -41,7 +41,7 @@ public class PrimitiveValueTest extends AbstractTest {
expected.clear(); expected.clear();
expected.set(2013, 0, 10, 21, 45, 17); expected.set(2013, 0, 10, 21, 45, 17);
final ODataValue value = getClient().getPrimitiveValueBuilder(). final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.TimeOfDay).setValue(expected).build(); setType(EdmPrimitiveTypeKind.TimeOfDay).setValue(expected).build();
assertEquals(EdmPrimitiveTypeKind.TimeOfDay, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.TimeOfDay, value.asPrimitive().getTypeKind());
@ -59,7 +59,7 @@ public class PrimitiveValueTest extends AbstractTest {
expected.clear(); expected.clear();
expected.set(2013, 0, 10); expected.set(2013, 0, 10);
final ODataValue value = getClient().getPrimitiveValueBuilder(). final ODataValue value = getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Date).setValue(expected).build(); setType(EdmPrimitiveTypeKind.Date).setValue(expected).build();
assertEquals(EdmPrimitiveTypeKind.Date, value.asPrimitive().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Date, value.asPrimitive().getTypeKind());

View File

@ -30,6 +30,20 @@ public abstract class AbstractODataValue implements ODataValue {
private static final long serialVersionUID = 7445422004232581877L; private static final long serialVersionUID = 7445422004232581877L;
/**
* Type name;
*/
private final String typeName;
public AbstractODataValue(String typeName) {
this.typeName = typeName;
}
@Override
public String getTypeName() {
return typeName;
}
/** /**
* Check is is a primitive value. * Check is is a primitive value.
* *

View File

@ -18,81 +18,29 @@
*/ */
package org.apache.olingo.commons.api.domain; package org.apache.olingo.commons.api.domain;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/** /**
* OData collection property value. * OData collection property value.
*/ */
public class ODataCollectionValue extends AbstractODataValue implements Iterable<ODataValue> { public interface ODataCollectionValue extends ODataValue, Iterable<ODataValue> {
private static final long serialVersionUID = -3665659846001987187L;
/**
* Type name;
*/
private final String typeName;
/**
* Values.
*/
private final List<ODataValue> values = new ArrayList<ODataValue>();
/**
* Constructor.
*
* @param typeName type name.
*/
public ODataCollectionValue(final String typeName) {
this.typeName = typeName;
}
/** /**
* Adds a value to the collection. * Adds a value to the collection.
* *
* @param value value to be added. * @param value value to be added.
*/ */
public void add(final ODataValue value) { void add(ODataValue value);
if (value.isPrimitive() || value.isComplex()) {
values.add(value);
}
}
/**
* Value iterator.
*
* @return value iterator.
*/
@Override
public Iterator<ODataValue> iterator() {
return values.iterator();
}
/**
* Gets value type name.
*
* @return value type name.
*/
public String getType() {
return typeName;
}
/**
* Gets collection size.
*
* @return collection size.
*/
public int size() {
return values.size();
}
/** /**
* Checks if collection is empty. * Checks if collection is empty.
* *
* @return 'TRUE' if empty; 'FALSE' otherwise. * @return 'TRUE' if empty; 'FALSE' otherwise.
*/ */
public boolean isEmpty() { boolean isEmpty();
return values.isEmpty();
} /**
* Gets collection size.
*
* @return collection size.
*/
int size();
} }

View File

@ -18,44 +18,17 @@
*/ */
package org.apache.olingo.commons.api.domain; package org.apache.olingo.commons.api.domain;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/** /**
* OData complex property value. * OData complex property value.
*/ */
public class ODataComplexValue extends AbstractODataValue implements Iterable<ODataProperty> { public interface ODataComplexValue extends ODataValue, Iterable<ODataProperty> {
private static final long serialVersionUID = -1878555027714020431L;
/**
* Type name.
*/
private final String typeName;
/**
* Complex type fields.
*/
private final Map<String, ODataProperty> fields = new LinkedHashMap<String, ODataProperty>();
/**
* Constructor.
*
* @param type type name.
*/
public ODataComplexValue(final String typeName) {
this.typeName = typeName;
}
/** /**
* Adds field to the complex type. * Adds field to the complex type.
* *
* @param field field to be added. * @param field field to be added.
*/ */
public void add(final ODataProperty field) { void add(ODataProperty field);
fields.put(field.getName(), field);
}
/** /**
* Gets field. * Gets field.
@ -63,35 +36,13 @@ public class ODataComplexValue extends AbstractODataValue implements Iterable<OD
* @param name name of the field to be retrieved. * @param name name of the field to be retrieved.
* @return requested field. * @return requested field.
*/ */
public ODataProperty get(final String name) { ODataProperty get(String name);
return fields.get(name);
}
/**
* Complex property fields iterator.
*
* @return fields iterator.
*/
@Override
public Iterator<ODataProperty> iterator() {
return fields.values().iterator();
}
/**
* Gest value type name.
*
* @return value type name.
*/
public String getType() {
return typeName;
}
/** /**
* Gets number of fields. * Gets number of fields.
* *
* @return number of fields. * @return number of fields.
*/ */
public int size() { int size();
return fields.size();
}
} }

View File

@ -19,80 +19,160 @@
package org.apache.olingo.commons.api.domain; package org.apache.olingo.commons.api.domain;
import java.net.URI; import java.net.URI;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.StringUtils;
/** /**
* OData entity. * OData entity.
*/ */
public class ODataEntity extends AbstractODataPayload implements ODataInvokeResult { public interface ODataEntity extends ODataInvokeResult {
private static final long serialVersionUID = 8360640095932811034L; String getName();
URI getLink();
/** /**
* Entity reference. * Gets ETag.
*/
private String reference;
/**
* ETag.
*/
private String eTag;
/**
* Media entity flag.
*/
private boolean mediaEntity = false;
/**
* In case of media entity, media content type.
*/
private String mediaContentType;
/**
* In case of media entity, media content source.
*/
private String mediaContentSource;
/**
* Edit link.
*/
protected URI editLink;
/**
* Navigation links (might contain in-line entities or feeds).
*/
protected final List<ODataLink> navigationLinks = new ArrayList<ODataLink>();
/**
* Association links.
*/
protected final List<ODataLink> associationLinks = new ArrayList<ODataLink>();
/**
* Media edit links.
*/
protected final List<ODataLink> editMediaLinks = new ArrayList<ODataLink>();
/**
* Operations (legacy, functions, actions).
*/
protected final List<ODataOperation> operations = new ArrayList<ODataOperation>();
/**
* Entity properties.
*/
protected final List<ODataProperty> properties = new ArrayList<ODataProperty>();
/**
* Constructor.
* *
* @param name OData entity name. * @return ETag.
*/ */
public ODataEntity(final String name) { String getETag();
super(name);
} /**
* Sets ETag.
*
* @param eTag ETag.
*/
void setETag(String eTag);
/**
* Searches for operation with given title.
*
* @param title operation to look for
* @return operation if found with given title, <tt>null</tt> otherwise
*/
ODataOperation getOperation(String title);
/**
* Gets operations.
*
* @return operations.
*/
List<ODataOperation> getOperations();
/**
* Searches for property with given name.
*
* @param name property to look for
* @return property if found with given name, <tt>null</tt> otherwise
*/
ODataProperty getProperty(String name);
/**
* Returns OData entity properties.
*
* @return OData entity properties.
*/
List<ODataProperty> getProperties();
/**
* Puts the given link into one of available lists, based on its type.
*
* @param link to be added
* @return <tt>true</tt> if the given link was added in one of available lists
*/
boolean addLink(ODataLink link);
/**
* Removes the given link from any list (association, navigation, edit-media).
*
* @param link to be removed
* @return <tt>true</tt> if the given link was contained in one of available lists
*/
boolean removeLink(ODataLink link);
/**
* Returns all entity association links.
*
* @return OData entity links.
*/
List<ODataLink> getAssociationLinks();
/**
* Returns all entity navigation links (including inline entities / feeds).
*
* @return OData entity links.
*/
List<ODataLink> getNavigationLinks();
/**
* Returns all entity media edit links.
*
* @return OData entity links.
*/
List<ODataLink> getEditMediaLinks();
/**
* Returns OData entity edit link.
*
* @return entity edit link.
*/
URI getEditLink();
/**
* Sets OData entity edit link.
*
* @param editLink edit link.
*/
void setEditLink(URI editLink);
/**
* TRUE if read-only entity.
*
* @return TRUE if read-only; FALSE otherwise.
*/
boolean isReadOnly();
/**
* Checks if the current entity is a media entity.
*
* @return 'TRUE' if media entity; 'FALSE' otherwise.
*/
boolean isMediaEntity();
/**
* Sets media entity flag.
*
* @param isMediaEntity media entity flag value.
*/
void setMediaEntity(boolean isMediaEntity);
/**
* Gets media content type.
*
* @return media content type.
*/
String getMediaContentType();
/**
* Sets media content type.
*
* @param mediaContentType media content type.
*/
void setMediaContentType(String mediaContentType);
/**
* Gets media content source.
*
* @return media content source.
*/
String getMediaContentSource();
/**
* Sets media content source.
*
* @param mediaContentSource media content source.
*/
void setMediaContentSource(String mediaContentSource);
/** /**
* To request entity references in place of the actual entities, the client issues a GET request with /$ref appended * To request entity references in place of the actual entities, the client issues a GET request with /$ref appended
@ -110,236 +190,8 @@ public class ODataEntity extends AbstractODataPayload implements ODataInvokeResu
* *
* @return entity reference. * @return entity reference.
*/ */
public String getReference() { String getReference();
return reference;
}
public void setReference(final String reference) { void setReference(String reference);
this.reference = reference;
}
/**
* Gets ETag.
*
* @return ETag.
*/
public String getETag() {
return eTag;
}
/**
* Sets ETag.
*
* @param eTag ETag.
*/
public void setETag(final String eTag) {
this.eTag = eTag;
}
/**
* Searches for operation with given title.
*
* @param title operation to look for
* @return operation if found with given title, <tt>null</tt> otherwise
*/
public ODataOperation getOperation(final String title) {
ODataOperation result = null;
for (ODataOperation operation : operations) {
if (title.equals(operation.getTitle())) {
result = operation;
}
}
return result;
}
/**
* Gets operations.
*
* @return operations.
*/
public List<ODataOperation> getOperations() {
return this.operations;
}
/**
* Searches for property with given name.
*
* @param name property to look for
* @return property if found with given name, <tt>null</tt> otherwise
*/
public ODataProperty getProperty(final String name) {
ODataProperty result = null;
if (StringUtils.isNotBlank(name)) {
for (ODataProperty property : properties) {
if (name.equals(property.getName())) {
result = property;
}
}
}
return result;
}
/**
* Returns OData entity properties.
*
* @return OData entity properties.
*/
public List<ODataProperty> getProperties() {
return properties;
}
/**
* Puts the given link into one of available lists, based on its type.
*
* @param link to be added
* @return <tt>true</tt> if the given link was added in one of available lists
*/
public boolean addLink(final ODataLink link) {
boolean result = false;
switch (link.getType()) {
case ASSOCIATION:
result = associationLinks.contains(link) ? false : associationLinks.add(link);
break;
case ENTITY_NAVIGATION:
case ENTITY_SET_NAVIGATION:
result = navigationLinks.contains(link) ? false : navigationLinks.add(link);
break;
case MEDIA_EDIT:
result = editMediaLinks.contains(link) ? false : editMediaLinks.add(link);
break;
default:
}
return result;
}
/**
* Removes the given link from any list (association, navigation, edit-media).
*
* @param link to be removed
* @return <tt>true</tt> if the given link was contained in one of available lists
*/
public boolean removeLink(final ODataLink link) {
return associationLinks.remove(link) || navigationLinks.remove(link) || editMediaLinks.remove(link);
}
/**
* Returns all entity navigation links (including inline entities / feeds).
*
* @return OData entity links.
*/
public List<ODataLink> getNavigationLinks() {
return navigationLinks;
}
/**
* Returns all entity association links.
*
* @return OData entity links.
*/
public List<ODataLink> getAssociationLinks() {
return associationLinks;
}
/**
* Returns all entity media edit links.
*
* @return OData entity links.
*/
public List<ODataLink> getEditMediaLinks() {
return editMediaLinks;
}
/**
* Returns OData entity edit link.
*
* @return entity edit link.
*/
public URI getEditLink() {
return editLink;
}
/**
* Sets OData entity edit link.
*
* @param editLink edit link.
*/
public void setEditLink(final URI editLink) {
this.editLink = editLink;
}
@Override
public URI getLink() {
return super.getLink() == null ? getEditLink() : super.getLink();
}
/**
* TRUE if read-only entity.
*
* @return TRUE if read-only; FALSE otherwise.
*/
public boolean isReadOnly() {
return super.getLink() != null;
}
/**
* Checks if the current entity is a media entity.
*
* @return 'TRUE' if media entity; 'FALSE' otherwise.
*/
public boolean isMediaEntity() {
return mediaEntity;
}
/**
* Sets media entity flag.
*
* @param isMediaEntity media entity flag value.
*/
public void setMediaEntity(final boolean isMediaEntity) {
this.mediaEntity = isMediaEntity;
}
/**
* Gets media content type.
*
* @return media content type.
*/
public String getMediaContentType() {
return mediaContentType;
}
/**
* Sets media content type.
*
* @param mediaContentType media content type.
*/
public void setMediaContentType(final String mediaContentType) {
this.mediaContentType = mediaContentType;
}
/**
* Gets media content source.
*
* @return media content source.
*/
public String getMediaContentSource() {
return mediaContentSource;
}
/**
* Sets media content source.
*
* @param mediaContentSource media content source.
*/
public void setMediaContentSource(final String mediaContentSource) {
this.mediaContentSource = mediaContentSource;
}
} }

View File

@ -19,102 +19,39 @@
package org.apache.olingo.commons.api.domain; package org.apache.olingo.commons.api.domain;
import java.net.URI; import java.net.URI;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* OData entity collection. If pagination was used to get this instance, forward page navigation URI will be available. * OData entity collection. If pagination was used to get this instance, forward page navigation URI will be available.
*/ */
public class ODataEntitySet extends AbstractODataPayload implements ODataInvokeResult { public interface ODataEntitySet extends ODataInvokeResult {
private static final long serialVersionUID = 9039605899821494024L;
/**
* Link to the next page.
*/
protected URI next;
/**
* Number of ODataEntities contained in this feed. If <tt>$inlinecount</tt> was requested, this value comes from
* there.
*/
protected Integer count;
/**
* OData entities contained in this feed.
*/
protected List<ODataEntity> entities = new ArrayList<ODataEntity>();
/**
* Constructor.
*/
public ODataEntitySet() {
super(null);
}
/**
* Constructor.
*
* @param next next link.
*/
public ODataEntitySet(final URI next) {
super(null);
this.next = next;
}
/** /**
* Gets next page link. * Gets next page link.
* *
* @return next page link; null value if single page or last page reached. * @return next page link; null value if single page or last page reached.
*/ */
public URI getNext() { URI getNext();
return next;
}
/**
* Sets in-line count.
*
* @param count in-line count value.
*/
public void setCount(final int count) {
this.count = count;
}
/**
* Gets in-line count.
*
* @return in-line count value.
*/
public int getCount() {
return count == null ? entities.size() : count;
}
/**
* Adds entity to the current feed.
*
* @param entity entity to be added.
* @return 'FALSE' if already exists; 'TRUE' otherwise.
*/
public boolean addEntity(final ODataEntity entity) {
return entities.contains(entity) ? false : entities.add(entity);
}
/**
* Removes an entity.
*
* @param entity entity to be removed.
* @return 'TRUE' in case of success; 'FALSE' otherwise.
*/
public boolean removeEntity(final ODataEntity entity) {
return entities.remove(entity);
}
/** /**
* Gets contained entities. * Gets contained entities.
* *
* @return feed entries. * @return feed entries.
*/ */
public List<ODataEntity> getEntities() { List<ODataEntity> getEntities();
return entities;
} /**
* Gets in-line count.
*
* @return in-line count value.
*/
int getCount();
/**
* Sets in-line count.
*
* @param count in-line count value.
*/
void setCount(final int count);
} }

View File

@ -22,11 +22,6 @@ import java.net.URI;
/** /**
* Entry point for generating OData domain objects. * Entry point for generating OData domain objects.
*
* @see ODataEntitySet
* @see ODataEntity
* @see ODataProperty
* @see ODataLink
*/ */
public interface ODataObjectFactory { public interface ODataObjectFactory {
@ -180,6 +175,12 @@ public interface ODataObjectFactory {
*/ */
ODataLink newMediaEditLink(String name, URI baseURI, String href); ODataLink newMediaEditLink(String name, URI baseURI, String href);
ODataPrimitiveValue.Builder newPrimitiveValueBuilder();
ODataComplexValue newComplexValue(String typeName);
ODataCollectionValue newCollectionValue(String typeName);
/** /**
* Instantiates a new primitive property. * Instantiates a new primitive property.
* *

View File

@ -19,141 +19,73 @@
package org.apache.olingo.commons.api.domain; package org.apache.olingo.commons.api.domain;
import java.io.Serializable; import java.io.Serializable;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/** /**
* OData entity property. * OData entity property.
*/ */
public class ODataProperty implements Serializable, ODataInvokeResult { public interface ODataProperty extends ODataInvokeResult, Serializable {
private static final long serialVersionUID = 926939448778950450L;
/**
* Property name.
*/
private final String name;
/**
* Property value.
*/
private ODataValue value;
/**
* Constructor.
*
* @param name property name.
* @param value property value.
*/
public ODataProperty(final String name, final ODataValue value) {
this.name = name;
this.value = value;
}
/** /**
* Returns property name. * Returns property name.
* *
* @return property name. * @return property name.
*/ */
public String getName() { String getName();
return name;
}
/**
* Returns property value.
*
* @return property value.
*/
public ODataValue getValue() {
return value;
}
/** /**
* Checks if has null value. * Checks if has null value.
* *
* @return 'TRUE' if has null value; 'FALSE' otherwise. * @return 'TRUE' if has null value; 'FALSE' otherwise.
*/ */
public boolean hasNullValue() { boolean hasNullValue();
return this.value == null;
}
/** /**
* Checks if has primitive value. * Checks if has primitive value.
* *
* @return 'TRUE' if has primitive value; 'FALSE' otherwise. * @return 'TRUE' if has primitive value; 'FALSE' otherwise.
*/ */
public boolean hasPrimitiveValue() { boolean hasPrimitiveValue();
return !hasNullValue() && this.value.isPrimitive();
}
/** /**
* Gets primitive value. * Gets primitive value.
* *
* @return primitive value if exists; null otherwise. * @return primitive value if exists; null otherwise.
*/ */
public ODataPrimitiveValue getPrimitiveValue() { ODataPrimitiveValue getPrimitiveValue();
return hasPrimitiveValue() ? this.value.asPrimitive() : null;
}
/** /**
* Checks if has complex value. * Returns property value.
* *
* @return 'TRUE' if has complex value; 'FALSE' otherwise. * @return property value.
*/ */
public boolean hasComplexValue() { ODataValue getValue();
return !hasNullValue() && this.value.isComplex();
}
/**
* Gets complex value.
*
* @return complex value if exists; null otherwise.
*/
public ODataComplexValue getComplexValue() {
return hasComplexValue() ? this.value.asComplex() : null;
}
/** /**
* Checks if has collection value. * Checks if has collection value.
* *
* @return 'TRUE' if has collection value; 'FALSE' otherwise. * @return 'TRUE' if has collection value; 'FALSE' otherwise.
*/ */
public boolean hasCollectionValue() { boolean hasCollectionValue();
return !hasNullValue() && this.value.isCollection();
}
/** /**
* Gets collection value. * Gets collection value.
* *
* @return collection value if exists; null otherwise. * @return collection value if exists; null otherwise.
*/ */
public ODataCollectionValue getCollectionValue() { ODataCollectionValue getCollectionValue();
return hasCollectionValue() ? this.value.asCollection() : null;
}
/** /**
* {@inheritDoc } * Checks if has complex value.
*
* @return 'TRUE' if has complex value; 'FALSE' otherwise.
*/ */
@Override boolean hasComplexValue();
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
/** /**
* {@inheritDoc } * Gets complex value.
*
* @return complex value if exists; null otherwise.
*/ */
@Override ODataComplexValue getComplexValue();
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* {@inheritDoc }
*/
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
} }

View File

@ -25,6 +25,13 @@ import java.io.Serializable;
*/ */
public interface ODataValue extends Serializable { public interface ODataValue extends Serializable {
/**
* Gets value type name.
*
* @return value type name.
*/
String getTypeName();
/** /**
* Check is is a primitive value. * Check is is a primitive value.
* *

View File

@ -0,0 +1,90 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.commons.core.domain;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.olingo.commons.api.domain.AbstractODataValue;
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
import org.apache.olingo.commons.api.domain.ODataValue;
/**
* OData collection property value.
*/
public class ODataCollectionValueImpl extends AbstractODataValue implements ODataCollectionValue {
private static final long serialVersionUID = -3665659846001987187L;
/**
* Values.
*/
private final List<ODataValue> values = new ArrayList<ODataValue>();
/**
* Constructor.
*
* @param typeName type name.
*/
public ODataCollectionValueImpl(final String typeName) {
super(typeName);
}
/**
* Adds a value to the collection.
*
* @param value value to be added.
*/
@Override
public void add(final ODataValue value) {
if (value.isPrimitive() || value.isComplex()) {
values.add(value);
}
}
/**
* Value iterator.
*
* @return value iterator.
*/
@Override
public Iterator<ODataValue> iterator() {
return values.iterator();
}
/**
* Gets collection size.
*
* @return collection size.
*/
@Override
public int size() {
return values.size();
}
/**
* Checks if collection is empty.
*
* @return 'TRUE' if empty; 'FALSE' otherwise.
*/
@Override
public boolean isEmpty() {
return values.isEmpty();
}
}

View File

@ -0,0 +1,89 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.commons.core.domain;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.olingo.commons.api.domain.AbstractODataValue;
import org.apache.olingo.commons.api.domain.ODataComplexValue;
import org.apache.olingo.commons.api.domain.ODataProperty;
/**
* OData complex property value.
*/
public class ODataComplexValueImpl extends AbstractODataValue implements ODataComplexValue {
private static final long serialVersionUID = -1878555027714020431L;
/**
* Complex type fields.
*/
private final Map<String, ODataProperty> fields = new LinkedHashMap<String, ODataProperty>();
/**
* Constructor.
*
* @param typeName type name.
*/
public ODataComplexValueImpl(final String typeName) {
super(typeName);
}
/**
* Adds field to the complex type.
*
* @param field field to be added.
*/
@Override
public void add(final ODataProperty field) {
fields.put(field.getName(), field);
}
/**
* Gets field.
*
* @param name name of the field to be retrieved.
* @return requested field.
*/
@Override
public ODataProperty get(final String name) {
return fields.get(name);
}
/**
* Complex property fields iterator.
*
* @return fields iterator.
*/
@Override
public Iterator<ODataProperty> iterator() {
return fields.values().iterator();
}
/**
* Gets number of fields.
*
* @return number of fields.
*/
@Override
public int size() {
return fields.size();
}
}

View File

@ -0,0 +1,372 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.commons.core.domain;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.domain.AbstractODataPayload;
import org.apache.olingo.commons.api.domain.ODataEntity;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.ODataOperation;
import org.apache.olingo.commons.api.domain.ODataProperty;
/**
* OData entity.
*/
public class ODataEntityImpl extends AbstractODataPayload implements ODataEntity {
private static final long serialVersionUID = 8360640095932811034L;
/**
* Entity reference.
*/
private String reference;
/**
* ETag.
*/
private String eTag;
/**
* Media entity flag.
*/
private boolean mediaEntity = false;
/**
* In case of media entity, media content type.
*/
private String mediaContentType;
/**
* In case of media entity, media content source.
*/
private String mediaContentSource;
/**
* Edit link.
*/
private URI editLink;
/**
* Navigation links (might contain in-line entities or feeds).
*/
private final List<ODataLink> navigationLinks = new ArrayList<ODataLink>();
/**
* Association links.
*/
private final List<ODataLink> associationLinks = new ArrayList<ODataLink>();
/**
* Media edit links.
*/
private final List<ODataLink> editMediaLinks = new ArrayList<ODataLink>();
/**
* Operations (legacy, functions, actions).
*/
private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
/**
* Entity properties.
*/
private final List<ODataProperty> properties = new ArrayList<ODataProperty>();
/**
* Constructor.
*
* @param name OData entity name.
*/
public ODataEntityImpl(final String name) {
super(name);
}
/**
* To request entity references in place of the actual entities, the client issues a GET request with /$ref appended
* to the resource path.
* <br />
* If the resource path does not identify an entity or a collection of entities, the service returns 404 Not Found.
* <br />
* If the resource path terminates on a collection, the response MUST be the format-specific representation of a
* collection of entity references pointing to the related entities. If no entities are related, the response is the
* format-specific representation of an empty collection.
* <br />
* If the resource path terminates on a single entity, the response MUST be the format-specific representation of an
* entity reference pointing to the related single entity. If the resource path terminates on a single entity and no
* such entity exists, the service returns 404 Not Found.
*
* @return entity reference.
*/
@Override
public String getReference() {
return reference;
}
@Override
public void setReference(final String reference) {
this.reference = reference;
}
/**
* Gets ETag.
*
* @return ETag.
*/
@Override
public String getETag() {
return eTag;
}
/**
* Sets ETag.
*
* @param eTag ETag.
*/
@Override
public void setETag(final String eTag) {
this.eTag = eTag;
}
/**
* Searches for operation with given title.
*
* @param title operation to look for
* @return operation if found with given title, <tt>null</tt> otherwise
*/
@Override
public ODataOperation getOperation(final String title) {
ODataOperation result = null;
for (ODataOperation operation : operations) {
if (title.equals(operation.getTitle())) {
result = operation;
}
}
return result;
}
/**
* Gets operations.
*
* @return operations.
*/
@Override
public List<ODataOperation> getOperations() {
return this.operations;
}
/**
* Searches for property with given name.
*
* @param name property to look for
* @return property if found with given name, <tt>null</tt> otherwise
*/
@Override
public ODataProperty getProperty(final String name) {
ODataProperty result = null;
if (StringUtils.isNotBlank(name)) {
for (ODataProperty property : properties) {
if (name.equals(property.getName())) {
result = property;
}
}
}
return result;
}
/**
* Returns OData entity properties.
*
* @return OData entity properties.
*/
@Override
public List<ODataProperty> getProperties() {
return properties;
}
/**
* Puts the given link into one of available lists, based on its type.
*
* @param link to be added
* @return <tt>true</tt> if the given link was added in one of available lists
*/
@Override
public boolean addLink(final ODataLink link) {
boolean result = false;
switch (link.getType()) {
case ASSOCIATION:
result = associationLinks.contains(link) ? false : associationLinks.add(link);
break;
case ENTITY_NAVIGATION:
case ENTITY_SET_NAVIGATION:
result = navigationLinks.contains(link) ? false : navigationLinks.add(link);
break;
case MEDIA_EDIT:
result = editMediaLinks.contains(link) ? false : editMediaLinks.add(link);
break;
default:
}
return result;
}
/**
* Removes the given link from any list (association, navigation, edit-media).
*
* @param link to be removed
* @return <tt>true</tt> if the given link was contained in one of available lists
*/
@Override
public boolean removeLink(final ODataLink link) {
return associationLinks.remove(link) || navigationLinks.remove(link) || editMediaLinks.remove(link);
}
/**
* Returns all entity navigation links (including inline entities / feeds).
*
* @return OData entity links.
*/
@Override
public List<ODataLink> getNavigationLinks() {
return navigationLinks;
}
/**
* Returns all entity association links.
*
* @return OData entity links.
*/
@Override
public List<ODataLink> getAssociationLinks() {
return associationLinks;
}
/**
* Returns all entity media edit links.
*
* @return OData entity links.
*/
@Override
public List<ODataLink> getEditMediaLinks() {
return editMediaLinks;
}
/**
* Returns OData entity edit link.
*
* @return entity edit link.
*/
@Override
public URI getEditLink() {
return editLink;
}
/**
* Sets OData entity edit link.
*
* @param editLink edit link.
*/
@Override
public void setEditLink(final URI editLink) {
this.editLink = editLink;
}
@Override
public URI getLink() {
return super.getLink() == null ? getEditLink() : super.getLink();
}
/**
* TRUE if read-only entity.
*
* @return TRUE if read-only; FALSE otherwise.
*/
@Override
public boolean isReadOnly() {
return super.getLink() != null;
}
/**
* Checks if the current entity is a media entity.
*
* @return 'TRUE' if media entity; 'FALSE' otherwise.
*/
@Override
public boolean isMediaEntity() {
return mediaEntity;
}
/**
* Sets media entity flag.
*
* @param isMediaEntity media entity flag value.
*/
@Override
public void setMediaEntity(final boolean isMediaEntity) {
this.mediaEntity = isMediaEntity;
}
/**
* Gets media content type.
*
* @return media content type.
*/
@Override
public String getMediaContentType() {
return mediaContentType;
}
/**
* Sets media content type.
*
* @param mediaContentType media content type.
*/
@Override
public void setMediaContentType(final String mediaContentType) {
this.mediaContentType = mediaContentType;
}
/**
* Gets media content source.
*
* @return media content source.
*/
@Override
public String getMediaContentSource() {
return mediaContentSource;
}
/**
* Sets media content source.
*
* @param mediaContentSource media content source.
*/
@Override
public void setMediaContentSource(final String mediaContentSource) {
this.mediaContentSource = mediaContentSource;
}
}

View File

@ -0,0 +1,104 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.commons.core.domain;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.commons.api.domain.AbstractODataPayload;
import org.apache.olingo.commons.api.domain.ODataEntity;
import org.apache.olingo.commons.api.domain.ODataEntitySet;
public class ODataEntitySetImpl extends AbstractODataPayload implements ODataEntitySet {
private static final long serialVersionUID = 9039605899821494024L;
/**
* Link to the next page.
*/
private URI next;
/**
* Number of ODataEntities contained in this feed. If <tt>$inlinecount</tt> was requested, this value comes from
* there.
*/
private Integer count;
/**
* OData entities contained in this feed.
*/
private List<ODataEntity> entities = new ArrayList<ODataEntity>();
/**
* Constructor.
*/
public ODataEntitySetImpl() {
super(null);
}
/**
* Constructor.
*
* @param next next link.
*/
public ODataEntitySetImpl(final URI next) {
super(null);
this.next = next;
}
/**
* Gets next page link.
*
* @return next page link; null value if single page or last page reached.
*/
@Override
public URI getNext() {
return next;
}
/**
* Gets contained entities.
*
* @return feed entries.
*/
@Override
public List<ODataEntity> getEntities() {
return entities;
}
/**
* Gets in-line count.
*
* @return in-line count value.
*/
@Override
public int getCount() {
return count == null ? entities.size() : count;
}
/**
* Sets in-line count.
*
* @param count in-line count value.
*/
@Override
public void setCount(final int count) {
this.count = count;
}
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.olingo.commons.core.op; package org.apache.olingo.commons.core.domain;
import java.net.URI; import java.net.URI;
import org.apache.olingo.commons.api.domain.ODataLinkType; import org.apache.olingo.commons.api.domain.ODataLinkType;
@ -44,22 +44,22 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
@Override @Override
public ODataEntitySet newEntitySet() { public ODataEntitySet newEntitySet() {
return new ODataEntitySet(); return new ODataEntitySetImpl();
} }
@Override @Override
public ODataEntitySet newEntitySet(final URI next) { public ODataEntitySet newEntitySet(final URI next) {
return new ODataEntitySet(next); return new ODataEntitySetImpl(next);
} }
@Override @Override
public ODataEntity newEntity(final String name) { public ODataEntity newEntity(final String name) {
return new ODataEntity(name); return new ODataEntityImpl(name);
} }
@Override @Override
public ODataEntity newEntity(final String name, final URI link) { public ODataEntity newEntity(final String name, final URI link) {
final ODataEntity result = new ODataEntity(name); final ODataEntityImpl result = new ODataEntityImpl(name);
result.setLink(link); result.setLink(link);
return result; return result;
} }
@ -138,19 +138,34 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build(); setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build();
} }
@Override
public ODataPrimitiveValue.Builder newPrimitiveValueBuilder() {
return new ODataPrimitiveValueImpl.BuilderImpl(version);
}
@Override
public ODataComplexValue newComplexValue(final String typeName) {
return new ODataComplexValueImpl(typeName);
}
@Override
public ODataCollectionValue newCollectionValue(final String typeName) {
return new ODataCollectionValueImpl(typeName);
}
@Override @Override
public ODataProperty newPrimitiveProperty(final String name, final ODataPrimitiveValue value) { public ODataProperty newPrimitiveProperty(final String name, final ODataPrimitiveValue value) {
return new ODataProperty(name, value); return new ODataPropertyImpl(name, value);
} }
@Override @Override
public ODataProperty newComplexProperty(final String name, final ODataComplexValue value) { public ODataProperty newComplexProperty(final String name, final ODataComplexValue value) {
return new ODataProperty(name, value); return new ODataPropertyImpl(name, value);
} }
@Override @Override
public ODataProperty newCollectionProperty(final String name, final ODataCollectionValue value) { public ODataProperty newCollectionProperty(final String name, final ODataCollectionValue value) {
return new ODataProperty(name, value); return new ODataPropertyImpl(name, value);
} }
} }

View File

@ -139,6 +139,15 @@ public class ODataPrimitiveValueImpl extends AbstractODataValue implements OData
*/ */
private Object value; private Object value;
private ODataPrimitiveValueImpl() {
super(null);
}
@Override
public String getTypeName() {
return typeKind.getFullQualifiedName().toString();
}
@Override @Override
public EdmPrimitiveTypeKind getTypeKind() { public EdmPrimitiveTypeKind getTypeKind() {
return typeKind; return typeKind;

View File

@ -0,0 +1,172 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.commons.core.domain;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
import org.apache.olingo.commons.api.domain.ODataComplexValue;
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
import org.apache.olingo.commons.api.domain.ODataProperty;
import org.apache.olingo.commons.api.domain.ODataValue;
/**
* OData entity property.
*/
public class ODataPropertyImpl implements ODataProperty {
private static final long serialVersionUID = 926939448778950450L;
/**
* Property name.
*/
private final String name;
/**
* Property value.
*/
private ODataValue value;
/**
* Constructor.
*
* @param name property name.
* @param value property value.
*/
public ODataPropertyImpl(final String name, final ODataValue value) {
this.name = name;
this.value = value;
}
/**
* Returns property name.
*
* @return property name.
*/
@Override
public String getName() {
return name;
}
/**
* Returns property value.
*
* @return property value.
*/
@Override
public ODataValue getValue() {
return value;
}
/**
* Checks if has null value.
*
* @return 'TRUE' if has null value; 'FALSE' otherwise.
*/
@Override
public boolean hasNullValue() {
return this.value == null;
}
/**
* Checks if has primitive value.
*
* @return 'TRUE' if has primitive value; 'FALSE' otherwise.
*/
@Override
public boolean hasPrimitiveValue() {
return !hasNullValue() && this.value.isPrimitive();
}
/**
* Gets primitive value.
*
* @return primitive value if exists; null otherwise.
*/
@Override
public ODataPrimitiveValue getPrimitiveValue() {
return hasPrimitiveValue() ? this.value.asPrimitive() : null;
}
/**
* Checks if has complex value.
*
* @return 'TRUE' if has complex value; 'FALSE' otherwise.
*/
@Override
public boolean hasComplexValue() {
return !hasNullValue() && this.value.isComplex();
}
/**
* Gets complex value.
*
* @return complex value if exists; null otherwise.
*/
@Override
public ODataComplexValue getComplexValue() {
return hasComplexValue() ? this.value.asComplex() : null;
}
/**
* Checks if has collection value.
*
* @return 'TRUE' if has collection value; 'FALSE' otherwise.
*/
@Override
public boolean hasCollectionValue() {
return !hasNullValue() && this.value.isCollection();
}
/**
* Gets collection value.
*
* @return collection value if exists; null otherwise.
*/
@Override
public ODataCollectionValue getCollectionValue() {
return hasCollectionValue() ? this.value.asCollection() : null;
}
/**
* {@inheritDoc }
*/
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
/**
* {@inheritDoc }
*/
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* {@inheritDoc }
*/
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}