Bunch of client API review

This commit is contained in:
Francesco Chicchiriccò 2014-05-23 12:32:30 +02:00
parent d0dd1ca9c5
commit 696c58645d
42 changed files with 130 additions and 265 deletions

View File

@ -301,7 +301,7 @@ class EntitySetInvocationHandler<
final List<ODataAnnotation> annotations = new ArrayList<ODataAnnotation>();
if (isSingleton) {
final ODataRetrieveResponse<org.apache.olingo.commons.api.domain.v4.Singleton> res =
final ODataRetrieveResponse<org.apache.olingo.commons.api.domain.v4.ODataSingleton> res =
((ODataClient) getClient()).getRetrieveRequestFactory().getSingletonRequest(uri).execute();
entities.add(res.getBody());

View File

@ -30,13 +30,11 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySe
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.uri.v3.URIBuilder;
import org.apache.olingo.client.api.uri.v3.URIBuilder.InlineCount;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.commons.core.data.AtomEntityImpl;
import org.junit.Test;
/**
@ -179,24 +177,4 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
assertEquals(1, customer.getNavigationLinks().size());
assertTrue((customer.getNavigationLinks().get(0) instanceof ODataInlineEntitySet));
}
@Test
public void issue131() {
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Customer").appendKeySegment(-7).select("Name");
ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(ODataPubFormat.ATOM);
final ODataEntity customer = req.execute().getBody();
assertEquals(0, customer.getProperties().size());
req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(ODataPubFormat.ATOM);
final Entity atomEntry =
client.getDeserializer().toEntity(req.execute().getRawResponse(), ODataPubFormat.ATOM).getPayload();
assertEquals("remotingdestructorprinterswitcheschannelssatellitelanguageresolve",
((AtomEntityImpl) atomEntry).getSummary());
}
}

View File

@ -38,7 +38,7 @@ public class ServiceDocumentTestITCase extends AbstractTestITCase {
assertEquals(200, res.getStatusCode());
final ODataServiceDocument serviceDocument = res.getBody();
assertEquals(24, serviceDocument.getEntitySetTitles().size());
assertEquals(24, serviceDocument.getEntitySetNames().size());
assertEquals(URI.create(testStaticServiceRootURL + "/ComputerDetail"),
serviceDocument.getEntitySetURI("ComputerDetail"));

View File

@ -38,7 +38,7 @@ import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.domain.v4.Singleton;
import org.apache.olingo.commons.api.domain.v4.ODataSingleton;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@ -50,10 +50,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
private void functions(final ODataPubFormat format) throws EdmPrimitiveTypeException {
// GetEmployeesCount
URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
final ODataEntityRequest<Singleton> singletonReq =
final ODataEntityRequest<ODataSingleton> singletonReq =
client.getRetrieveRequestFactory().getSingletonRequest(builder.build());
singletonReq.setFormat(format);
final Singleton company = singletonReq.execute().getBody();
final ODataSingleton company = singletonReq.execute().getBody();
assertNotNull(company);
ODataOperation boundOp = company.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount");

View File

@ -25,7 +25,6 @@ import static org.junit.Assert.assertFalse;
import org.junit.Test;
import java.net.URI;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
@ -213,12 +212,12 @@ public class ConformanceTestITCase extends AbstractTestITCase {
new FullQualifiedName("Microsoft.Test.OData.Services.OpenTypesServiceV4.RowIndex"));
getClient().getBinder().add(rowIndex,
getClient().getObjectFactory().newPrimitiveProperty("Id",
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
// add property not in metadata
getClient().getBinder().add(rowIndex,
getClient().getObjectFactory().newPrimitiveProperty("aString",
getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("string")));
getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("string")));
// add navigation property not in metadata
rowIndex.addLink(client.getObjectFactory().newEntityNavigationLink(
@ -226,7 +225,7 @@ public class ConformanceTestITCase extends AbstractTestITCase {
final ODataEntityCreateRequest<ODataEntity> createReq = getClient().getCUDRequestFactory().
getEntityCreateRequest(getClient().newURIBuilder(testOpenTypeServiceRootURL).
appendEntitySetSegment("RowIndex").build(), rowIndex);
appendEntitySetSegment("RowIndex").build(), rowIndex);
final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
assertEquals(201, createRes.getStatusCode());
@ -234,7 +233,6 @@ public class ConformanceTestITCase extends AbstractTestITCase {
final URIBuilder builder = getClient().newURIBuilder(testOpenTypeServiceRootURL).
appendEntitySetSegment("RowIndex").appendKeySegment(id);
rowIndex = read(ODataPubFormat.JSON_FULL_METADATA, builder.build());
assertNotNull(rowIndex);
assertEquals(EdmPrimitiveTypeKind.Int32, rowIndex.getProperty("Id").getPrimitiveValue().getTypeKind());
@ -310,10 +308,10 @@ public class ConformanceTestITCase extends AbstractTestITCase {
final ODataEntity entity = res.getBody();
assertNotNull(entity);
assertTrue(entity.getReference().endsWith("/StaticService/V40/Static.svc/Customers(PersonID=1)"));
assertTrue(entity.getId().toASCIIString().endsWith("/StaticService/V40/Static.svc/Customers(PersonID=1)"));
final URI referenceURI =
client.newURIBuilder(testStaticServiceRootURL).appendEntityIdSegment(entity.getReference()).build();
final URI referenceURI = client.newURIBuilder(testStaticServiceRootURL).
appendEntityIdSegment(entity.getId().toASCIIString()).build();
req = client.getRetrieveRequestFactory().getEntityRequest(referenceURI);
req.setFormat(ODataPubFormat.JSON_FULL_METADATA);

View File

@ -180,7 +180,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
assertNull(entitySet);
final ResWrap<ODataEntity> entity = res.getBodyAs(ODataEntity.class);
assertTrue(entity.getPayload().getReference().endsWith("/StaticService/V40/Static.svc/People(5)"));
assertTrue(entity.getPayload().getId().toASCIIString().endsWith("/StaticService/V40/Static.svc/People(5)"));
}
@Test
@ -284,10 +284,10 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
final ODataEntity entity = res.getBody();
assertNotNull(entity);
assertTrue(entity.getReference().endsWith("/StaticService/V40/Static.svc/Customers(PersonID=1)"));
assertTrue(entity.getId().toASCIIString().endsWith("/StaticService/V40/Static.svc/Customers(PersonID=1)"));
final URI referenceURI =
client.newURIBuilder(testStaticServiceRootURL).appendEntityIdSegment(entity.getReference()).build();
final URI referenceURI = client.newURIBuilder(testStaticServiceRootURL).
appendEntityIdSegment(entity.getId().toASCIIString()).build();
req = client.getRetrieveRequestFactory().getEntityRequest(referenceURI);
req.setFormat(format);

View File

@ -224,7 +224,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase {
assertEquals("W/\"A1FF3E230954908F\"", entity.getMetadataETag());
assertEquals("W/\"A1FF3E230954908G\"", entity.getPayload().getETag());
assertEquals("Model.VipCustomer", entity.getPayload().getType());
assertEquals("http://host/service/Employees(PersonID=3)", entity.getPayload().getId());
assertEquals("http://host/service/Employees(PersonID=3)", entity.getPayload().getId().toASCIIString());
assertEquals("People(976)", entity.getPayload().getEditLink().getHref());
assertEquals("Employees(1)/$value", entity.getPayload().getMediaContentSource().toASCIIString());
assertEquals("image/jpeg", entity.getPayload().getMediaContentType());

View File

@ -176,12 +176,12 @@ public class PropertyTestITCase extends AbstractTestITCase {
public void createAndDelete() {
// 1. create
final ODataEntity category = client.getObjectFactory().newEntity(null);
category.setReference(client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Categories").appendKeySegment(1).build().toASCIIString());
category.setId(client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Categories").appendKeySegment(1).build());
final URIBuilder createBuilder = client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Products").appendKeySegment(0).appendNavigationSegment("Categories").
appendRefSegment();
appendRefSegment();
final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().
getEntityCreateRequest(createBuilder.build(), category);

View File

@ -32,7 +32,7 @@ import org.apache.olingo.client.api.uri.v4.URIBuilder;
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
import org.apache.olingo.commons.api.domain.v4.ODataValuable;
import org.apache.olingo.commons.api.domain.v4.Singleton;
import org.apache.olingo.commons.api.domain.v4.ODataSingleton;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataPubFormat;
@ -42,10 +42,10 @@ public class SingletonTestITCase extends AbstractTestITCase {
private void read(final ODataClient client, final ODataPubFormat format) throws EdmPrimitiveTypeException {
final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
final ODataEntityRequest<Singleton> singleton =
final ODataEntityRequest<ODataSingleton> singleton =
client.getRetrieveRequestFactory().getSingletonRequest(builder.build());
singleton.setFormat(format);
final Singleton company = singleton.execute().getBody();
final ODataSingleton company = singleton.execute().getBody();
assertNotNull(company);
assertEquals(0, company.getProperty("CompanyID").getPrimitiveValue().toCastValue(Integer.class), 0);
@ -74,11 +74,11 @@ public class SingletonTestITCase extends AbstractTestITCase {
throws EdmPrimitiveTypeException {
final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Boss");
final ODataEntityRequest<Singleton> singleton =
final ODataEntityRequest<ODataSingleton> singleton =
client.getRetrieveRequestFactory().getSingletonRequest(builder.build());
singleton.setFormat(format);
singleton.setPrefer(client.newPreferences().includeAnnotations("*"));
final Singleton boss = singleton.execute().getBody();
final ODataSingleton boss = singleton.execute().getBody();
assertNotNull(boss);
assertFalse(boss.getAnnotations().isEmpty());
@ -102,20 +102,20 @@ public class SingletonTestITCase extends AbstractTestITCase {
}
private void update(final ODataPubFormat format) throws EdmPrimitiveTypeException {
final Singleton changes = getClient().getObjectFactory().newSingleton(
final ODataSingleton changes = getClient().getObjectFactory().newSingleton(
new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Company"));
changes.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Revenue",
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt64(132520L)));
final URI uri = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company").build();
final ODataEntityUpdateRequest<Singleton> req = getClient().getCUDRequestFactory().
final ODataEntityUpdateRequest<ODataSingleton> req = getClient().getCUDRequestFactory().
getSingletonUpdateRequest(uri, UpdateType.PATCH, changes);
req.setFormat(format);
final ODataEntityUpdateResponse<Singleton> res = req.execute();
final ODataEntityUpdateResponse<ODataSingleton> res = req.execute();
assertEquals(204, res.getStatusCode());
final Singleton updated = getClient().getRetrieveRequestFactory().getSingletonRequest(uri).execute().getBody();
final ODataSingleton updated = getClient().getRetrieveRequestFactory().getSingletonRequest(uri).execute().getBody();
assertNotNull(updated);
assertEquals(132520, updated.getProperty("Revenue").getPrimitiveValue().toCastValue(Integer.class), 0);
}

View File

@ -21,12 +21,14 @@ package org.apache.olingo.client.api.communication.request.cud.v4;
import java.net.URI;
import org.apache.olingo.client.api.communication.request.cud.CommonCUDRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
import org.apache.olingo.commons.api.domain.v4.Singleton;
import org.apache.olingo.commons.api.domain.v4.ODataSingleton;
public interface CUDRequestFactory extends CommonCUDRequestFactory<UpdateType> {
ODataEntityUpdateRequest<Singleton> getSingletonUpdateRequest(URI targetURI, UpdateType type, Singleton changes);
ODataEntityUpdateRequest<ODataSingleton> getSingletonUpdateRequest(
URI targetURI, UpdateType type, ODataSingleton changes);
ODataEntityUpdateRequest<Singleton> getSingletonUpdateRequest(UpdateType type, Singleton entity);
ODataEntityUpdateRequest<ODataSingleton> getSingletonUpdateRequest(
UpdateType type, ODataSingleton entity);
}

View File

@ -27,7 +27,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataProperty
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.domain.v4.Singleton;
import org.apache.olingo.commons.api.domain.v4.ODataSingleton;
@SuppressWarnings("unchecked")
public interface RetrieveRequestFactory extends CommonRetrieveRequestFactory {
@ -38,7 +38,7 @@ public interface RetrieveRequestFactory extends CommonRetrieveRequestFactory {
@Override
ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> getEntitySetIteratorRequest(URI uri);
ODataEntityRequest<Singleton> getSingletonRequest(URI uri);
ODataEntityRequest<ODataSingleton> getSingletonRequest(URI uri);
@Override
ODataEntityRequest<ODataEntity> getEntityRequest(URI uri);

View File

@ -52,14 +52,6 @@ public interface ServiceDocument {
*/
ServiceDocumentItem getEntitySetByName(String name);
/**
* Gets top level entity set with given title.
*
* @param title entity set title
* @return entity set with given title if found, otherwise null
*/
ServiceDocumentItem getEntitySetByTitle(String title);
/**
* Gets top level function imports.
*
@ -67,7 +59,7 @@ public interface ServiceDocument {
*/
List<ServiceDocumentItem> getFunctionImports();
/**
/*
* Gets top level function import set with given name.
*
* @param name function import name
@ -75,14 +67,6 @@ public interface ServiceDocument {
*/
ServiceDocumentItem getFunctionImportByName(String name);
/**
* Gets top level function import with given title.
*
* @param title function import title
* @return function import with given title if found, otherwise null
*/
ServiceDocumentItem getFunctionImportByTitle(String title);
/**
* Gets top level singletons.
*
@ -98,26 +82,10 @@ public interface ServiceDocument {
*/
ServiceDocumentItem getSingletonByName(String name);
/**
* Gets top level singleton with given title.
*
* @param title singleton title
* @return singleton with given title if found, otherwise null
*/
ServiceDocumentItem getSingletonByTitle(String title);
/**
* Gets related service documents.
*
* @return related service documents.
*/
List<ServiceDocumentItem> getRelatedServiceDocuments();
/**
* Gets related service document with given title.
*
* @param title related service document title
* @return related service document with given title if found, otherwise null
*/
ServiceDocumentItem getRelatedServiceDocumentByTitle(String title);
}

View File

@ -16,15 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.api.data;
public interface ServiceDocumentItem {
String getHref();
String getName();
String getTitle();
String getUrl();
}

View File

@ -24,7 +24,7 @@ import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.api.communication.request.cud.v4.CUDRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
import org.apache.olingo.client.core.communication.request.cud.AbstractCUDRequestFactory;
import org.apache.olingo.commons.api.domain.v4.Singleton;
import org.apache.olingo.commons.api.domain.v4.ODataSingleton;
public class CUDRequestFactoryImpl extends AbstractCUDRequestFactory<UpdateType>
implements CUDRequestFactory {
@ -36,15 +36,15 @@ public class CUDRequestFactoryImpl extends AbstractCUDRequestFactory<UpdateType>
}
@Override
public ODataEntityUpdateRequest<Singleton> getSingletonUpdateRequest(
final UpdateType type, final Singleton entity) {
public ODataEntityUpdateRequest<ODataSingleton> getSingletonUpdateRequest(
final UpdateType type, final ODataSingleton entity) {
return super.getEntityUpdateRequest(type, entity);
}
@Override
public ODataEntityUpdateRequest<Singleton> getSingletonUpdateRequest(
final URI targetURI, final UpdateType type, final Singleton changes) {
public ODataEntityUpdateRequest<ODataSingleton> getSingletonUpdateRequest(
final URI targetURI, final UpdateType type, final ODataSingleton changes) {
return super.getEntityUpdateRequest(targetURI, type, changes);
}

View File

@ -35,7 +35,7 @@ import org.apache.olingo.client.core.communication.request.retrieve.ODataPropert
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.domain.v4.Singleton;
import org.apache.olingo.commons.api.domain.v4.ODataSingleton;
@SuppressWarnings("unchecked")
public class RetrieveRequestFactoryImpl extends AbstractRetrieveRequestFactory
@ -64,8 +64,8 @@ public class RetrieveRequestFactoryImpl extends AbstractRetrieveRequestFactory
}
@Override
public ODataEntityRequest<Singleton> getSingletonRequest(final URI uri) {
return new ODataEntityRequestImpl<Singleton>(client, uri);
public ODataEntityRequest<ODataSingleton> getSingletonRequest(final URI uri) {
return new ODataEntityRequestImpl<ODataSingleton>(client, uri);
}
@Override

View File

@ -87,16 +87,6 @@ public abstract class AbstractServiceDocument implements ServiceDocument {
return result;
}
protected ServiceDocumentItem getByTitle(final List<ServiceDocumentItem> elements, final String title) {
ServiceDocumentItem result = null;
for (ServiceDocumentItem element : elements) {
if (title.equals(element.getTitle())) {
result = element;
}
}
return result;
}
@Override
public List<ServiceDocumentItem> getEntitySets() {
return entitySets;
@ -107,11 +97,6 @@ public abstract class AbstractServiceDocument implements ServiceDocument {
return getByName(getEntitySets(), name);
}
@Override
public ServiceDocumentItem getEntitySetByTitle(final String title) {
return getByTitle(getEntitySets(), title);
}
@Override
public List<ServiceDocumentItem> getFunctionImports() {
return Collections.<ServiceDocumentItem>emptyList();
@ -122,11 +107,6 @@ public abstract class AbstractServiceDocument implements ServiceDocument {
return getByName(getFunctionImports(), name);
}
@Override
public ServiceDocumentItem getFunctionImportByTitle(final String title) {
return getByTitle(getFunctionImports(), title);
}
@Override
public List<ServiceDocumentItem> getSingletons() {
return Collections.<ServiceDocumentItem>emptyList();
@ -137,21 +117,11 @@ public abstract class AbstractServiceDocument implements ServiceDocument {
return getByName(getSingletons(), name);
}
@Override
public ServiceDocumentItem getSingletonByTitle(final String title) {
return getByTitle(getSingletons(), title);
}
@Override
public List<ServiceDocumentItem> getRelatedServiceDocuments() {
return Collections.<ServiceDocumentItem>emptyList();
}
@Override
public ServiceDocumentItem getRelatedServiceDocumentByTitle(final String title) {
return getByTitle(getRelatedServiceDocuments(), title);
}
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);

View File

@ -73,10 +73,7 @@ public class JSONServiceDocumentDeserializer extends ODataJacksonDeserializer<Re
final ServiceDocumentItemImpl item = new ServiceDocumentItemImpl();
item.setName(node.get("name").asText());
if (node.has("title")) {
item.setTitle(node.get("title").asText());
}
item.setHref(node.get("url").asText());
item.setUrl(node.get("url").asText());
final String kind = node.has("kind") ? node.get("kind").asText() : null;
if (StringUtils.isBlank(kind) || "EntitySet".equals(kind)) {

View File

@ -18,8 +18,6 @@
*/
package org.apache.olingo.client.core.data;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
@ -30,10 +28,7 @@ public class ServiceDocumentItemImpl implements ServiceDocumentItem {
private String name;
private String title;
@JsonProperty("url")
private String href;
private String url;
@Override
public String getName() {
@ -45,21 +40,12 @@ public class ServiceDocumentItemImpl implements ServiceDocumentItem {
}
@Override
public String getTitle() {
return title;
public String getUrl() {
return url;
}
public void setTitle(final String title) {
this.title = title;
}
@Override
public String getHref() {
return href;
}
public void setHref(final String href) {
this.href = href;
public void setUrl(final String url) {
this.url = url;
}
@Override

View File

@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
public class XMLServiceDocumentDeserializer extends ODataJacksonDeserializer<ResWrap<ServiceDocument>> {
private String getTitle(final JsonParser jp) throws IOException {
private String getName(final JsonParser jp) throws IOException {
String title = jp.nextTextValue();
if (title == null) {
jp.nextToken();
@ -56,11 +56,9 @@ public class XMLServiceDocumentDeserializer extends ODataJacksonDeserializer<Res
final JsonToken token = jp.getCurrentToken();
if (token == JsonToken.FIELD_NAME) {
if ("href".equals(jp.getCurrentName())) {
element.setHref(jp.nextTextValue());
} else if ("name".equals(jp.getCurrentName())) {
element.setName(jp.nextTextValue());
element.setUrl(jp.nextTextValue());
} else if ("title".equals(jp.getCurrentName())) {
element.setTitle(getTitle(jp));
element.setName(getName(jp));
}
}
}
@ -95,7 +93,7 @@ public class XMLServiceDocumentDeserializer extends ODataJacksonDeserializer<Res
jp.nextToken();
jp.nextToken();
if ("title".equals(jp.getCurrentName())) {
sdoc.setTitle(getTitle(jp));
sdoc.setTitle(getName(jp));
}
} else if ("collection".equals(jp.getCurrentName())) {
jp.nextToken();

View File

@ -98,10 +98,8 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
final ODataServiceDocument serviceDocument = new ODataServiceDocument();
for (ServiceDocumentItem entitySet : resource.getEntitySets()) {
// handles V3 JSON format oddities, where title is not contained
serviceDocument.getEntitySets().put(StringUtils.isBlank(entitySet.getTitle())
? entitySet.getName() : entitySet.getTitle(),
URIUtils.getURI(resource.getBaseURI(), entitySet.getHref()));
serviceDocument.getEntitySets().
put(entitySet.getName(), URIUtils.getURI(resource.getBaseURI(), entitySet.getUrl()));
}
return serviceDocument;

View File

@ -105,18 +105,18 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
for (ServiceDocumentItem functionImport : resource.getFunctionImports()) {
serviceDocument.getFunctionImports().put(
functionImport.getName() == null ? functionImport.getHref() : functionImport.getName(),
URIUtils.getURI(resource.getBaseURI(), functionImport.getHref()));
functionImport.getName() == null ? functionImport.getUrl() : functionImport.getName(),
URIUtils.getURI(resource.getBaseURI(), functionImport.getUrl()));
}
for (ServiceDocumentItem singleton : resource.getSingletons()) {
serviceDocument.getSingletons().put(
singleton.getName() == null ? singleton.getHref() : singleton.getName(),
URIUtils.getURI(resource.getBaseURI(), singleton.getHref()));
singleton.getName() == null ? singleton.getUrl() : singleton.getName(),
URIUtils.getURI(resource.getBaseURI(), singleton.getUrl()));
}
for (ServiceDocumentItem sdoc : resource.getRelatedServiceDocuments()) {
serviceDocument.getRelatedServiceDocuments().put(
sdoc.getName() == null ? sdoc.getHref() : sdoc.getName(),
URIUtils.getURI(resource.getBaseURI(), sdoc.getHref()));
sdoc.getName() == null ? sdoc.getUrl() : sdoc.getName(),
URIUtils.getURI(resource.getBaseURI(), sdoc.getUrl()));
}
return serviceDocument;
@ -175,7 +175,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
@Override
public Entity getEntity(final CommonODataEntity odataEntity, final Class<? extends Entity> reference) {
final Entity entity = super.getEntity(odataEntity, reference);
entity.setId(((ODataEntity) odataEntity).getReference());
entity.setId(((ODataEntity) odataEntity).getId());
annotations((ODataEntity) odataEntity, entity, reference);
return entity;
}
@ -274,7 +274,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
public ODataEntity getODataEntity(final ResWrap<Entity> resource) {
final ODataEntity entity = (ODataEntity) super.getODataEntity(resource);
entity.setReference(resource.getPayload().getId());
entity.setId(resource.getPayload().getId());
odataAnnotations(resource.getPayload(), entity);
return entity;

View File

@ -43,7 +43,7 @@ public class ServiceDocumentTest extends AbstractTest {
final ODataServiceDocument serviceDocument = getClient().getReader().readServiceDocument(
getClass().getResourceAsStream("serviceDocument." + getFileExtension(format)), format);
assertNotNull(serviceDocument);
assertTrue(serviceDocument.getEntitySetTitles().contains("Persons"));
assertTrue(serviceDocument.getEntitySetNames().contains("Persons"));
}
@Test

View File

@ -74,7 +74,7 @@ public class EntitySetTest extends AbstractTest {
assertNotNull(entitySet);
for (ODataEntity entity : entitySet.getEntities()) {
assertNotNull(entity.getReference());
assertNotNull(entity.getId());
}
entitySet.setCount(entitySet.getEntities().size());

View File

@ -266,7 +266,7 @@ public class EntityTest extends AbstractTest {
getClient().getDeserializer().toEntity(input, format));
assertNotNull(entity);
assertNotNull(entity.getReference());
assertNotNull(entity.getId());
final ODataEntity written = getClient().getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, getClient().getBinder().

View File

@ -52,7 +52,7 @@ public class ServiceDocumentTest extends AbstractTest {
final ODataServiceDocument serviceDocument = getClient().getBinder().getODataServiceDocument(service.getPayload());
assertNotNull(serviceDocument);
assertTrue(serviceDocument.getEntitySetTitles().contains("Order Details"));
assertTrue(serviceDocument.getEntitySetNames().contains("Order Details"));
assertEquals(URI.create("http://host/service/TopProducts"),
serviceDocument.getFunctionImportURI("TopProducts"));
assertEquals(URI.create("http://host/HR/"),

View File

@ -25,6 +25,7 @@
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
version="1.0">
<xsl:template match="atom:summary"/>
<xsl:template match="atom:updated"/>
<xsl:template match="atom:author"/>
<xsl:template match="atom:title">

View File

@ -8,19 +8,16 @@
"url": "Orders"
},
{
"name": "OrderItems",
"title": "Order Details",
"name": "Order Details",
"url": "OrderItems"
},
{
"name": "TopProducts",
"title": "Best-Selling Products",
"kind": "FunctionImport",
"url": "TopProducts"
},
{
"name": "Contoso",
"title": "Contoso Ltd.",
"kind": "Singleton",
"url": "Contoso"
},

View File

@ -34,7 +34,7 @@
<atom:title type="text">Order Details</atom:title>
</app:collection>
<metadata:function-import href="TopProducts">
<atom:title>Best-Selling Products</atom:title>
<atom:title>TopProducts</atom:title>
</metadata:function-import>
<metadata:singleton href="Contoso">
<atom:title>Contoso Ltd.</atom:title>

View File

@ -57,14 +57,14 @@ public interface Entity extends Linked, Annotatable {
*
* @return entity ID.
*/
String getId();
URI getId();
/**
* Sets entity ID.
*
* @param id entity ID.
*/
void setId(String id);
void setId(URI id);
/**
* Gets entity self link.

View File

@ -49,7 +49,7 @@ public interface EntitySet extends Annotatable {
*
* @return ID.
*/
String getId();
URI getId();
/**
* Gets entities.

View File

@ -38,11 +38,11 @@ public class ODataServiceDocument {
}
/**
* Gets entity set titles.
* Gets entity set names.
*
* @return entity set titles.
* @return entity set names.
*/
public Collection<String> getEntitySetTitles() {
public Collection<String> getEntitySetNames() {
return entitySets.keySet();
}
@ -58,11 +58,11 @@ public class ODataServiceDocument {
/**
* Gets URI about the given entity set.
*
* @param title title.
* @param name name.
* @return URI.
*/
public URI getEntitySetURI(final String title) {
return entitySets.get(title);
public URI getEntitySetURI(final String name) {
return entitySets.get(name);
}
public Map<String, URI> getFunctionImports() {
@ -70,11 +70,11 @@ public class ODataServiceDocument {
}
/**
* Gets function import titles.
* Gets function import names.
*
* @return function import titles.
* @return function import names.
*/
public Collection<String> getFunctionImportTitles() {
public Collection<String> getFunctionImportNames() {
return functionImports.keySet();
}
@ -90,11 +90,11 @@ public class ODataServiceDocument {
/**
* Gets URI of the given function import.
*
* @param title title.
* @param name name.
* @return URI.
*/
public URI getFunctionImportURI(final String title) {
return functionImports.get(title);
public URI getFunctionImportURI(final String name) {
return functionImports.get(name);
}
public Map<String, URI> getSingletons() {
@ -102,11 +102,11 @@ public class ODataServiceDocument {
}
/**
* Gets singleton titles.
* Gets singleton names.
*
* @return singleton titles.
* @return singleton names.
*/
public Collection<String> getSingletonTitles() {
public Collection<String> getSingletonNames() {
return singletons.keySet();
}
@ -122,11 +122,11 @@ public class ODataServiceDocument {
/**
* Gets URI of the given singleton.
*
* @param title title.
* @param name name.
* @return URI.
*/
public URI getSingletonURI(final String title) {
return singletons.get(title);
public URI getSingletonURI(final String name) {
return singletons.get(name);
}
public Map<String, URI> getRelatedServiceDocuments() {
@ -134,11 +134,11 @@ public class ODataServiceDocument {
}
/**
* Gets related service documents titles.
* Gets related service documents names.
*
* @return related service documents titles.
* @return related service documents names.
*/
public Collection<String> getRelatedServiceDocumentsTitles() {
public Collection<String> getRelatedServiceDocumentsNames() {
return relatedServiceDocuments.keySet();
}
@ -154,10 +154,10 @@ public class ODataServiceDocument {
/**
* Gets URI of the given related service documents.
*
* @param title title.
* @param name name.
* @return URI.
*/
public URI getRelatedServiceDocumentURI(final String title) {
return relatedServiceDocuments.get(title);
public URI getRelatedServiceDocumentURI(final String name) {
return relatedServiceDocuments.get(name);
}
}

View File

@ -18,6 +18,7 @@
*/
package org.apache.olingo.commons.api.domain.v4;
import java.net.URI;
import java.util.List;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
@ -45,8 +46,8 @@ public interface ODataEntity extends CommonODataEntity, ODataAnnotatable {
*
* @return entity reference.
*/
String getReference();
URI getId();
void setReference(String reference);
void setId(URI id);
}

View File

@ -40,7 +40,7 @@ public interface ODataObjectFactory extends CommonODataObjectFactory {
@Override
ODataEntity newEntity(FullQualifiedName typeName, URI link);
Singleton newSingleton(FullQualifiedName typeName);
ODataSingleton newSingleton(FullQualifiedName typeName);
@Override
ODataLink newEntitySetNavigationLink(String name, URI link);

View File

@ -18,5 +18,5 @@
*/
package org.apache.olingo.commons.api.domain.v4;
public interface Singleton extends ODataEntity {
public interface ODataSingleton extends ODataEntity {
}

View File

@ -18,27 +18,19 @@
*/
package org.apache.olingo.commons.core.data;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import java.net.URI;
import java.text.ParseException;
import java.util.Date;
abstract class AbstractODataObject extends AbstractAnnotatedObject {
private static final long serialVersionUID = -4391162864875546927L;
private static final ISO8601DateFormat ISO_DATEFORMAT = new ISO8601DateFormat();
private URI baseURI;
private String id;
private URI id;
private String title;
private String summary;
private Date updated;
public URI getBaseURI() {
return baseURI;
}
@ -47,11 +39,11 @@ abstract class AbstractODataObject extends AbstractAnnotatedObject {
this.baseURI = baseURI == null ? null : URI.create(baseURI);
}
public String getId() {
public URI getId() {
return id;
}
public void setId(final String id) {
public void setId(final URI id) {
this.id = id;
}
@ -59,23 +51,11 @@ abstract class AbstractODataObject extends AbstractAnnotatedObject {
return title;
}
public String getSummary() {
return summary;
}
public Date getUpdated() {
return updated;
}
public void setCommonProperty(final String key, final String value) throws ParseException {
if ("id".equals(key)) {
this.id = value;
this.id = URI.create(value);
} else if ("title".equals(key)) {
this.title = value;
} else if ("summary".equals(key)) {
this.summary = value;
} else if ("updated".equals(key)) {
this.updated = ISO_DATEFORMAT.parse(value);
}
}
}

View File

@ -567,7 +567,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
final Attribute entityRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
if (entityRefId != null) {
entity.setId(entityRefId.getValue());
entity.setId(URI.create(entityRefId.getValue()));
}
return entity;

View File

@ -205,13 +205,6 @@ public class AtomSerializer extends AbstractAtomDealer {
writer.writeCharacters(object.getTitle());
writer.writeEndElement();
}
if (StringUtils.isNotBlank(object.getSummary())) {
writer.writeStartElement(Constants.ATOM_ELEM_SUMMARY);
writer.writeAttribute(Constants.ATTR_TYPE, "text");
writer.writeCharacters(object.getSummary());
writer.writeEndElement();
}
}
private void properties(final XMLStreamWriter writer, final List<Property> properties) throws XMLStreamException {
@ -261,9 +254,9 @@ public class AtomSerializer extends AbstractAtomDealer {
Constants.ATOM_ATTR_ETAG, entity.getETag());
}
if (StringUtils.isNotBlank(entity.getId())) {
if (entity.getId() != null) {
writer.writeStartElement(Constants.ATOM_ELEM_ID);
writer.writeCharacters(entity.getId());
writer.writeCharacters(entity.getId().toASCIIString());
writer.writeEndElement();
}
@ -332,14 +325,14 @@ public class AtomSerializer extends AbstractAtomDealer {
private void entityRef(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException {
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF);
writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId());
writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId().toASCIIString());
}
private void entityRef(final XMLStreamWriter writer, final ResWrap<Entity> container) throws XMLStreamException {
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF);
writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
addContextInfo(writer, container);
writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().getId());
writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().getId().toASCIIString());
}
private void entity(final Writer outWriter, final Entity entity) throws XMLStreamException {
@ -396,9 +389,9 @@ public class AtomSerializer extends AbstractAtomDealer {
writer.writeEndElement();
}
if (StringUtils.isNotBlank(entitySet.getId())) {
if (entitySet.getId() != null) {
writer.writeStartElement(Constants.ATOM_ELEM_ID);
writer.writeCharacters(entitySet.getId());
writer.writeCharacters(entitySet.getId().toASCIIString());
writer.writeEndElement();
}

View File

@ -96,7 +96,7 @@ public class JSONEntityDeserializer extends AbstractJsonDeserializer<JSONEntityI
}
if (tree.hasNonNull(jsonId)) {
entity.setId(tree.get(jsonId).textValue());
entity.setId(URI.create(tree.get(jsonId).textValue()));
tree.remove(jsonId);
}

View File

@ -76,7 +76,7 @@ public class JSONEntitySerializer extends AbstractJsonSerializer<JSONEntityImpl>
}
if (entity.getId() != null) {
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entity.getId());
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entity.getId().toASCIIString());
}
for (Annotation annotation : entity.getAnnotations()) {

View File

@ -64,7 +64,7 @@ public class JSONEntitySetSerializer extends AbstractJsonSerializer<JSONEntitySe
}
if (entitySet.getId() != null) {
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entitySet.getId());
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entitySet.getId().toASCIIString());
}
jgen.writeNumberField(version.getJSONMap().get(ODataServiceVersion.JSON_COUNT),
entitySet.getCount() == null ? entitySet.getEntities().size() : entitySet.getCount());

View File

@ -18,23 +18,24 @@
*/
package org.apache.olingo.commons.core.domain.v4;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.domain.v4.Singleton;
import org.apache.olingo.commons.api.domain.v4.ODataSingleton;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.core.domain.AbstractODataEntity;
public class ODataEntityImpl extends AbstractODataEntity implements ODataEntity, Singleton {
public class ODataEntityImpl extends AbstractODataEntity implements ODataEntity, ODataSingleton {
private static final long serialVersionUID = -3997704808753685990L;
/**
* Entity reference.
* Entity id.
*/
private String reference;
private URI id;
private final List<ODataProperty> properties = new ArrayList<ODataProperty>();
@ -45,13 +46,13 @@ public class ODataEntityImpl extends AbstractODataEntity implements ODataEntity,
}
@Override
public String getReference() {
return reference;
public URI getId() {
return id;
}
@Override
public void setReference(final String reference) {
this.reference = reference;
public void setId(final URI id) {
this.id = id;
}
@Override

View File

@ -33,7 +33,7 @@ import org.apache.olingo.commons.api.domain.v4.ODataLink;
import org.apache.olingo.commons.api.domain.v4.ODataLinkedComplexValue;
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.domain.v4.ODataValue;
import org.apache.olingo.commons.api.domain.v4.Singleton;
import org.apache.olingo.commons.api.domain.v4.ODataSingleton;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.domain.AbstractODataObjectFactory;
@ -67,7 +67,7 @@ public class ODataObjectFactoryImpl extends AbstractODataObjectFactory implement
}
@Override
public Singleton newSingleton(final FullQualifiedName typeName) {
public ODataSingleton newSingleton(final FullQualifiedName typeName) {
return new ODataEntityImpl(typeName);
}