[OLINGO-244] Implementation and IT provided

This commit is contained in:
Francesco Chicchiriccò 2014-04-14 14:11:43 +02:00
parent 1585f2da4f
commit d5e29b0207
29 changed files with 506 additions and 328 deletions

View File

@ -216,13 +216,14 @@ public abstract class AbstractServices {
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response mergeEntity(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) String ifMatch,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
final String changes) {
return patchEntity(accept, prefer, ifMatch, entitySetName, entityId, changes);
return patchEntity(accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
}
@PATCH
@ -231,6 +232,7 @@ public abstract class AbstractServices {
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response patchEntity(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) String ifMatch,
@PathParam("entitySetName") String entitySetName,
@ -245,7 +247,7 @@ public abstract class AbstractServices {
}
final AbstractUtilities util = acceptType == Accept.ATOM ? xml : json;
InputStream res =
final InputStream res =
util.patchEntity(entitySetName, entityId, IOUtils.toInputStream(changes), acceptType, ifMatch);
final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
@ -294,6 +296,7 @@ public abstract class AbstractServices {
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response replaceEntity(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@ -782,7 +785,7 @@ public abstract class AbstractServices {
final Map.Entry<String, InputStream> entityInfo =
utils.getValue().readEntity(entitySetName, entityId, Accept.ATOM);
InputStream entity = entityInfo.getValue();
final InputStream entity = entityInfo.getValue();
final FITAtomDeserializer atomDeserializer = Commons.getAtomDeserializer(version);
final AtomSerializer atomSerializer = Commons.getAtomSerializer(version);
@ -1355,219 +1358,6 @@ public abstract class AbstractServices {
return xml.createResponse(stream, Commons.getETag(basePath, version), acceptType);
}
/**
* Retrieve links sample.
*
* @param accept Accept header.
* @param entitySetName Entity set name.
* @param entityId entity id.
* @param linkName link name.
* @param format format query option.
* @return links.
*/
@GET
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response getLinks(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
if (StringUtils.isNotBlank(format)) {
acceptType = Accept.valueOf(format.toUpperCase());
} else {
acceptType = Accept.parse(accept, version);
}
if (acceptType == Accept.ATOM) {
throw new UnsupportedMediaTypeException("Unsupported media type");
}
final LinkInfo links = xml.readLinks(entitySetName, entityId, linkName, acceptType);
return xml.createResponse(
links.getLinks(),
links.getEtag(),
acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
}
@POST
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response postLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
String link,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
if (StringUtils.isNotBlank(format)) {
acceptType = Accept.valueOf(format.toUpperCase());
} else {
acceptType = Accept.parse(accept, version);
}
if (acceptType == Accept.ATOM) {
throw new UnsupportedMediaTypeException("Unsupported media type");
}
final Accept content;
if (StringUtils.isNotBlank(contentType)) {
content = Accept.parse(contentType, version);
} else {
content = acceptType;
}
final AbstractUtilities utils = getUtilities(acceptType);
final List<String> links;
if (content == Accept.XML || content == Accept.TEXT || content == Accept.ATOM) {
links = xml.extractLinkURIs(IOUtils.toInputStream(link)).getValue();
} else {
links = json.extractLinkURIs(IOUtils.toInputStream(link)).getValue();
}
utils.putLinksInMemory(
Commons.getEntityBasePath(entitySetName, entityId),
entitySetName,
entityId,
linkName,
links);
return xml.createResponse(null, null, null, Response.Status.NO_CONTENT);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
}
@MERGE
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response mergeLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
String link,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return putLink(accept, contentType, entitySetName, entityId, linkName, link, format);
}
@PATCH
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response patchLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
String link,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return putLink(accept, contentType, entitySetName, entityId, linkName, link, format);
}
@PUT
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response putLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
String link,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
if (StringUtils.isNotBlank(format)) {
acceptType = Accept.valueOf(format.toUpperCase());
} else {
acceptType = Accept.parse(accept, version);
}
if (acceptType == Accept.ATOM) {
throw new UnsupportedMediaTypeException("Unsupported media type");
}
final Accept content;
if (StringUtils.isNotBlank(contentType)) {
content = Accept.parse(contentType, version);
} else {
content = acceptType;
}
final AbstractUtilities utils = getUtilities(acceptType);
final List<String> links;
if (content == Accept.XML || content == Accept.TEXT || content == Accept.ATOM) {
links = xml.extractLinkURIs(IOUtils.toInputStream(link)).getValue();
} else {
links = json.extractLinkURIs(IOUtils.toInputStream(link)).getValue();
}
utils.putLinksInMemory(
Commons.getEntityBasePath(entitySetName, entityId),
entitySetName,
linkName,
links);
return xml.createResponse(null, null, null, Response.Status.NO_CONTENT);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
}
@DELETE
@Path("/{entitySetName}({entityId})/$links/{linkName}({linkId})")
public Response deleteLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
@PathParam("linkId") String linkId,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
if (StringUtils.isNotBlank(format)) {
acceptType = Accept.valueOf(format.toUpperCase());
} else {
acceptType = Accept.parse(accept, version);
}
if (acceptType == Accept.ATOM) {
throw new UnsupportedMediaTypeException("Unsupported media type");
}
final AbstractUtilities utils = getUtilities(acceptType);
final Map.Entry<String, List<String>> currents = json.extractLinkURIs(utils.readLinks(
entitySetName, entityId, linkName, Accept.JSON_FULLMETA).getLinks());
final Map.Entry<String, List<String>> toBeRemoved = json.extractLinkURIs(utils.readLinks(
entitySetName, entityId, linkName + "(" + linkId + ")", Accept.JSON_FULLMETA).getLinks());
final List<String> remains = currents.getValue();
remains.removeAll(toBeRemoved.getValue());
utils.putLinksInMemory(
Commons.getEntityBasePath(entitySetName, entityId),
entitySetName,
linkName,
remains);
return xml.createResponse(null, null, null, Response.Status.NO_CONTENT);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
}
/**
* Count sample.
*
@ -1609,7 +1399,7 @@ public abstract class AbstractServices {
return new AbstractMap.SimpleEntry<Accept, AbstractUtilities>(acceptType, getUtilities(acceptType));
}
private AbstractUtilities getUtilities(final Accept accept) {
protected AbstractUtilities getUtilities(final Accept accept) {
final AbstractUtilities utils;
if (accept == Accept.XML || accept == Accept.TEXT || accept == Accept.ATOM) {
utils = xml;

View File

@ -105,13 +105,15 @@ public class V3KeyAsSegment {
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response mergeEntity(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) String ifMatch,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
final String changes) {
return replaceServiceName(services.patchEntity(accept, prefer, ifMatch, entitySetName, entityId, changes));
return replaceServiceName(
services.patchEntity(accept, contentType, prefer, ifMatch, entitySetName, entityId, changes));
}
@PATCH
@ -120,13 +122,15 @@ public class V3KeyAsSegment {
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response patchEntity(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) String ifMatch,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
final String changes) {
return replaceServiceName(services.patchEntity(accept, prefer, ifMatch, entitySetName, entityId, changes));
return replaceServiceName(
services.patchEntity(accept, contentType, prefer, ifMatch, entitySetName, entityId, changes));
}
@PUT
@ -135,12 +139,14 @@ public class V3KeyAsSegment {
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response putNewEntity(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
final String entity) {
return replaceServiceName(services.replaceEntity(accept, prefer, entitySetName, entityId, entity));
return replaceServiceName(
services.replaceEntity(accept, contentType, prefer, entitySetName, entityId, entity));
}
@POST

View File

@ -19,23 +19,35 @@
package org.apache.olingo.fit;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import org.apache.olingo.fit.utils.XHTTPMethodInterceptor;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.interceptor.InInterceptors;
import org.apache.olingo.commons.api.data.Feed;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.fit.methods.MERGE;
import org.apache.olingo.fit.methods.PATCH;
import org.apache.olingo.fit.utils.AbstractUtilities;
import org.apache.olingo.fit.utils.Accept;
import org.apache.olingo.fit.utils.Commons;
import org.apache.olingo.fit.utils.ConstantKey;
import org.apache.olingo.fit.utils.Constants;
import org.apache.olingo.fit.utils.FSManager;
import org.apache.olingo.fit.utils.LinkInfo;
import org.springframework.stereotype.Service;
@Service
@ -94,4 +106,218 @@ public class V3Services extends AbstractServices {
feed.setCount(feed.getEntries().size());
}
}
/**
* Retrieve links sample.
*
* @param accept Accept header.
* @param entitySetName Entity set name.
* @param entityId entity id.
* @param linkName link name.
* @param format format query option.
* @return links.
*/
@GET
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response getLinks(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
if (StringUtils.isNotBlank(format)) {
acceptType = Accept.valueOf(format.toUpperCase());
} else {
acceptType = Accept.parse(accept, version);
}
if (acceptType == Accept.ATOM) {
throw new UnsupportedMediaTypeException("Unsupported media type");
}
final LinkInfo links = xml.readLinks(entitySetName, entityId, linkName, acceptType);
return xml.createResponse(
links.getLinks(),
links.getEtag(),
acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
}
@POST
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response postLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
String link,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
if (StringUtils.isNotBlank(format)) {
acceptType = Accept.valueOf(format.toUpperCase());
} else {
acceptType = Accept.parse(accept, version);
}
if (acceptType == Accept.ATOM) {
throw new UnsupportedMediaTypeException("Unsupported media type");
}
final Accept content;
if (StringUtils.isNotBlank(contentType)) {
content = Accept.parse(contentType, version);
} else {
content = acceptType;
}
final AbstractUtilities utils = getUtilities(acceptType);
final List<String> links;
if (content == Accept.XML || content == Accept.TEXT || content == Accept.ATOM) {
links = xml.extractLinkURIs(IOUtils.toInputStream(link)).getValue();
} else {
links = json.extractLinkURIs(IOUtils.toInputStream(link)).getValue();
}
utils.putLinksInMemory(
Commons.getEntityBasePath(entitySetName, entityId),
entitySetName,
entityId,
linkName,
links);
return xml.createResponse(null, null, null, Response.Status.NO_CONTENT);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
}
@MERGE
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response mergeLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
String link,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return putLink(accept, contentType, entitySetName, entityId, linkName, link, format);
}
@PATCH
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response patchLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
String link,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return putLink(accept, contentType, entitySetName, entityId, linkName, link, format);
}
@PUT
@Path("/{entitySetName}({entityId})/$links/{linkName}")
public Response putLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
String link,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
if (StringUtils.isNotBlank(format)) {
acceptType = Accept.valueOf(format.toUpperCase());
} else {
acceptType = Accept.parse(accept, version);
}
if (acceptType == Accept.ATOM) {
throw new UnsupportedMediaTypeException("Unsupported media type");
}
final Accept content;
if (StringUtils.isNotBlank(contentType)) {
content = Accept.parse(contentType, version);
} else {
content = acceptType;
}
final AbstractUtilities utils = getUtilities(acceptType);
final List<String> links;
if (content == Accept.XML || content == Accept.TEXT || content == Accept.ATOM) {
links = xml.extractLinkURIs(IOUtils.toInputStream(link)).getValue();
} else {
links = json.extractLinkURIs(IOUtils.toInputStream(link)).getValue();
}
utils.putLinksInMemory(
Commons.getEntityBasePath(entitySetName, entityId),
entitySetName,
linkName,
links);
return xml.createResponse(null, null, null, Response.Status.NO_CONTENT);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
}
@DELETE
@Path("/{entitySetName}({entityId})/$links/{linkName}({linkId})")
public Response deleteLink(
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId,
@PathParam("linkName") String linkName,
@PathParam("linkId") String linkId,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
if (StringUtils.isNotBlank(format)) {
acceptType = Accept.valueOf(format.toUpperCase());
} else {
acceptType = Accept.parse(accept, version);
}
if (acceptType == Accept.ATOM) {
throw new UnsupportedMediaTypeException("Unsupported media type");
}
final AbstractUtilities utils = getUtilities(acceptType);
final Map.Entry<String, List<String>> currents = json.extractLinkURIs(utils.readLinks(
entitySetName, entityId, linkName, Accept.JSON_FULLMETA).getLinks());
final Map.Entry<String, List<String>> toBeRemoved = json.extractLinkURIs(utils.readLinks(
entitySetName, entityId, linkName + "(" + linkId + ")", Accept.JSON_FULLMETA).getLinks());
final List<String> remains = currents.getValue();
remains.removeAll(toBeRemoved.getValue());
utils.putLinksInMemory(
Commons.getEntityBasePath(entitySetName, entityId),
entitySetName,
linkName,
remains);
return xml.createResponse(null, null, null, Response.Status.NO_CONTENT);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
}
}

View File

@ -18,8 +18,11 @@
*/
package org.apache.olingo.fit;
import javax.ws.rs.NotFoundException;
import org.apache.olingo.fit.utils.XHTTPMethodInterceptor;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.interceptor.InInterceptors;
import org.apache.olingo.commons.api.data.Feed;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
@ -41,4 +44,39 @@ public class V4Services extends AbstractServices {
feed.setCount(feed.getEntries().size());
}
}
@Override
public Response patchEntity(
final String accept,
final String contentType,
final String prefer,
final String ifMatch,
final String entitySetName,
final String entityId,
final String changes) {
final Response response =
getEntityInternal(accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
return response.getStatus() >= 400
? postNewEntity(accept, contentType, prefer, entitySetName, changes)
: super.patchEntity(accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
}
@Override
public Response replaceEntity(
final String accept,
final String contentType,
final String prefer,
final String entitySetName,
final String entityId,
final String entity) {
try {
getEntityInternal(accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
return super.replaceEntity(accept, contentType, prefer, entitySetName, entityId, entity);
} catch (NotFoundException e) {
return postNewEntity(accept, contentType, prefer, entitySetName, entityId);
}
}
}

View File

@ -78,17 +78,19 @@ public enum Accept {
public static Accept parse(final String contentType, final ODataServiceVersion version, final Accept def) {
if (StringUtils.isBlank(contentType) || allTypesPattern.matcher(contentType).matches()) {
return def;
} else if (JSON_NOMETA.toString(version).equals(contentType)) {
} else if (contentType.startsWith(JSON_NOMETA.toString(version))) {
return JSON_NOMETA;
} else if (JSON.toString(version).equals(contentType) || "application/json".equals(contentType)) {
return JSON;
} else if (JSON_FULLMETA.toString(version).equals(contentType)) {
} else if (contentType.startsWith(JSON_FULLMETA.toString(version))) {
return JSON_FULLMETA;
} else if (XML.toString(version).equals(contentType)) {
} else if (contentType.startsWith(JSON.toString(version))
|| contentType.startsWith(ContentType.APPLICATION_JSON.getMimeType())) {
return JSON;
} else if (contentType.startsWith(XML.toString(version))) {
return XML;
} else if (ATOM.toString(version).equals(contentType)) {
} else if (contentType.startsWith(ATOM.toString(version))) {
return ATOM;
} else if (TEXT.toString(version).equals(contentType)) {
} else if (contentType.startsWith(TEXT.toString(version))) {
return TEXT;
} else {
throw new UnsupportedMediaTypeException("Unsupported media type");

View File

@ -21,6 +21,7 @@ package org.apache.olingo.client.api;
import org.apache.olingo.client.api.communication.header.ODataHeaders;
import org.apache.olingo.client.api.communication.request.batch.CommonBatchRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.CommonCUDRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
import org.apache.olingo.client.api.communication.request.invoke.CommonInvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.CommonRetrieveRequestFactory;
import org.apache.olingo.client.api.communication.request.streamed.CommonStreamedRequestFactory;
@ -34,7 +35,7 @@ import org.apache.olingo.client.api.uri.CommonURIBuilder;
import org.apache.olingo.client.api.uri.CommonFilterFactory;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
public interface CommonODataClient {
public interface CommonODataClient<UT extends CommonUpdateType> {
ODataServiceVersion getServiceVersion();
@ -60,7 +61,7 @@ public interface CommonODataClient {
CommonRetrieveRequestFactory getRetrieveRequestFactory();
CommonCUDRequestFactory getCUDRequestFactory();
CommonCUDRequestFactory<UT> getCUDRequestFactory();
CommonStreamedRequestFactory getStreamedRequestFactory();

View File

@ -21,14 +21,15 @@ package org.apache.olingo.client.api.communication.request.cud;
import java.io.Serializable;
import java.net.URI;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
/**
* OData request factory class.
*
* @param <UT> concrete UpdateType.
*/
public interface CommonCUDRequestFactory extends Serializable {
public interface CommonCUDRequestFactory<UT extends CommonUpdateType> extends Serializable {
/**
* Gets a create request object instance.
@ -45,14 +46,12 @@ public interface CommonCUDRequestFactory extends Serializable {
/**
* Gets an update request object instance.
*
* @param <UT> concrete UpdateType.
* @param targetURI edit link of the object to be updated.
* @param type type of update to be performed.
* @param changes changes to be applied.
* @return new ODataEntityUpdateRequest instance.
*/
<UT extends UpdateType> ODataEntityUpdateRequest getEntityUpdateRequest(URI targetURI, UT type,
CommonODataEntity changes);
ODataEntityUpdateRequest getEntityUpdateRequest(URI targetURI, UT type, CommonODataEntity changes);
/**
* Gets an update request object instance; uses entity's edit link as endpoint.
@ -61,7 +60,7 @@ public interface CommonCUDRequestFactory extends Serializable {
* @param entity changes to be applied.
* @return new ODataEntityUpdateRequest instance.
*/
ODataEntityUpdateRequest getEntityUpdateRequest(UpdateType type, CommonODataEntity entity);
ODataEntityUpdateRequest getEntityUpdateRequest(UT type, CommonODataEntity entity);
/**
* Gets a create request object instance.
@ -73,7 +72,7 @@ public interface CommonCUDRequestFactory extends Serializable {
* @param value value to be created.
* @return new ODataValueUpdateRequest instance.
*/
ODataValueUpdateRequest getValueUpdateRequest(URI targetURI, UpdateType type, ODataPrimitiveValue value);
ODataValueUpdateRequest getValueUpdateRequest(URI targetURI, UT type, ODataPrimitiveValue value);
/**
* Gets an update request object instance.
@ -96,8 +95,7 @@ public interface CommonCUDRequestFactory extends Serializable {
* @param property value to be update.
* @return new ODataPropertyUpdateRequest instance.
*/
ODataPropertyUpdateRequest getPropertyComplexValueUpdateRequest(
URI targetURI, UpdateType type, CommonODataProperty property);
ODataPropertyUpdateRequest getPropertyComplexValueUpdateRequest(URI targetURI, UT type, CommonODataProperty property);
/**
* Gets an update request object instance.
@ -110,31 +108,6 @@ public interface CommonCUDRequestFactory extends Serializable {
*/
ODataPropertyUpdateRequest getPropertyCollectionValueUpdateRequest(URI targetURI, CommonODataProperty property);
/**
* Gets an add link request object instance.
* <br/>
* Use this kind of request to create a navigation link between existing entities.
*
* @param targetURI navigation property's link collection.
* @param link navigation link to be added.
* @return new ODataLinkCreateRequest instance.
*/
ODataLinkCreateRequest getLinkCreateRequest(URI targetURI, ODataLink link);
/**
* Gets a link update request object instance.
* <br/>
* Use this kind of request to update a navigation link between existing entities.
* <br/>
* In case of the old navigation link doesn't exist the new one will be added as well.
*
* @param targetURI navigation property's link collection.
* @param type type of update to be performed.
* @param link URL that identifies the entity to be linked.
* @return new ODataLinkUpdateRequest instance.
*/
ODataLinkUpdateRequest getLinkUpdateRequest(URI targetURI, UpdateType type, ODataLink link);
/**
* Gets a delete request object instance.
* <br/>

View File

@ -20,7 +20,7 @@ package org.apache.olingo.client.api.communication.request.cud;
import org.apache.olingo.client.api.http.HttpMethod;
public interface UpdateType {
public interface CommonUpdateType {
/**
* Gets HTTP request method.

View File

@ -18,7 +18,34 @@
*/
package org.apache.olingo.client.api.communication.request.cud.v3;
import java.net.URI;
import org.apache.olingo.client.api.communication.request.cud.CommonCUDRequestFactory;
import org.apache.olingo.commons.api.domain.ODataLink;
public interface CUDRequestFactory extends CommonCUDRequestFactory {
public interface CUDRequestFactory extends CommonCUDRequestFactory<UpdateType> {
/**
* Gets an add link request object instance.
* <br/>
* Use this kind of request to create a navigation link between existing entities.
*
* @param targetURI navigation property's link collection.
* @param link navigation link to be added.
* @return new ODataLinkCreateRequest instance.
*/
ODataLinkCreateRequest getLinkCreateRequest(URI targetURI, ODataLink link);
/**
* Gets a link update request object instance.
* <br/>
* Use this kind of request to update a navigation link between existing entities.
* <br/>
* In case of the old navigation link doesn't exist the new one will be added as well.
*
* @param targetURI navigation property's link collection.
* @param type type of update to be performed.
* @param link URL that identifies the entity to be linked.
* @return new ODataLinkUpdateRequest instance.
*/
ODataLinkUpdateRequest getLinkUpdateRequest(URI targetURI, UpdateType type, ODataLink link);
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.api.communication.request.cud;
package org.apache.olingo.client.api.communication.request.cud.v3;
import org.apache.olingo.client.api.communication.request.ODataBasicRequest;
import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.api.communication.request.cud;
package org.apache.olingo.client.api.communication.request.cud.v3;
import org.apache.olingo.client.api.communication.request.ODataBasicRequest;
import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;

View File

@ -18,12 +18,13 @@
*/
package org.apache.olingo.client.api.communication.request.cud.v3;
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
import org.apache.olingo.client.api.http.HttpMethod;
/**
* Update type.
*/
public enum UpdateType implements org.apache.olingo.client.api.communication.request.cud.UpdateType {
public enum UpdateType implements CommonUpdateType {
/**
* Replace all and remove missing attributes.

View File

@ -18,7 +18,20 @@
*/
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.ODataEntity;
public interface CUDRequestFactory extends CommonCUDRequestFactory {
public interface CUDRequestFactory extends CommonCUDRequestFactory<UpdateType> {
/**
* Gets an update request object instance; uses given URL as endpoint (for upsert).
*
* @param type type of update to be performed
* @param uri endpoint for upsert
* @param entity entity to be upserted.
* @return new ODataEntityUpdateRequest instance.
*/
ODataEntityUpdateRequest getEntityUpsertRequest(final UpdateType type, URI uri, ODataEntity entity);
}

View File

@ -18,12 +18,13 @@
*/
package org.apache.olingo.client.api.communication.request.cud.v4;
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
import org.apache.olingo.client.api.http.HttpMethod;
/**
* Update type.
*/
public enum UpdateType implements org.apache.olingo.client.api.communication.request.cud.UpdateType {
public enum UpdateType implements CommonUpdateType {
/**
* Replace all and remove missing attributes.

View File

@ -21,6 +21,7 @@ package org.apache.olingo.client.api.v3;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
import org.apache.olingo.client.api.communication.request.invoke.v3.InvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.v3.RetrieveRequestFactory;
import org.apache.olingo.client.api.communication.request.streamed.v3.StreamedRequestFactory;
@ -31,7 +32,7 @@ import org.apache.olingo.client.api.uri.v3.URIBuilder;
import org.apache.olingo.client.api.uri.v3.FilterFactory;
import org.apache.olingo.commons.api.domain.v3.ODataObjectFactory;
public interface ODataClient extends CommonODataClient {
public interface ODataClient extends CommonODataClient<UpdateType> {
@Override
Configuration getConfiguration();

View File

@ -21,6 +21,7 @@ package org.apache.olingo.client.api.v4;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory;
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.api.communication.request.invoke.v4.InvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.v4.RetrieveRequestFactory;
import org.apache.olingo.client.api.communication.request.streamed.v4.StreamedRequestFactory;
@ -31,7 +32,7 @@ import org.apache.olingo.client.api.uri.v4.URIBuilder;
import org.apache.olingo.client.api.uri.v4.FilterFactory;
import org.apache.olingo.commons.api.domain.v4.ODataObjectFactory;
public interface ODataClient extends CommonODataClient {
public interface ODataClient extends CommonODataClient<UpdateType> {
@Override
Configuration getConfiguration();

View File

@ -19,10 +19,11 @@
package org.apache.olingo.client.core;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
import org.apache.olingo.client.api.op.ODataWriter;
import org.apache.olingo.client.core.op.ODataWriterImpl;
public abstract class AbstractODataClient implements CommonODataClient {
public abstract class AbstractODataClient<UT extends CommonUpdateType> implements CommonODataClient<UT> {
private static final long serialVersionUID = 7269096702397630265L;

View File

@ -21,21 +21,18 @@ package org.apache.olingo.client.core.communication.request.cud;
import java.net.URI;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.cud.CommonCUDRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataLinkCreateRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataLinkUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataValueUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.UpdateType;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
public abstract class AbstractCUDRequestFactory implements CommonCUDRequestFactory {
public abstract class AbstractCUDRequestFactory<UT extends CommonUpdateType> implements CommonCUDRequestFactory<UT> {
private static final long serialVersionUID = -2723641791198745990L;
@ -54,7 +51,7 @@ public abstract class AbstractCUDRequestFactory implements CommonCUDRequestFacto
@Override
public ODataEntityUpdateRequest getEntityUpdateRequest(
final URI targetURI, final UpdateType type, final CommonODataEntity changes) {
final URI targetURI, final UT type, final CommonODataEntity changes) {
final ODataEntityUpdateRequest req;
@ -69,7 +66,7 @@ public abstract class AbstractCUDRequestFactory implements CommonCUDRequestFacto
}
@Override
public ODataEntityUpdateRequest getEntityUpdateRequest(final UpdateType type, final CommonODataEntity entity) {
public ODataEntityUpdateRequest getEntityUpdateRequest(final UT type, final CommonODataEntity entity) {
if (entity.getEditLink() == null) {
throw new IllegalArgumentException("No edit link found");
}
@ -88,7 +85,7 @@ public abstract class AbstractCUDRequestFactory implements CommonCUDRequestFacto
@Override
public ODataValueUpdateRequest getValueUpdateRequest(
final URI targetURI, final UpdateType type, final ODataPrimitiveValue value) {
final URI targetURI, final UT type, final ODataPrimitiveValue value) {
final ODataValueUpdateRequest req;
@ -124,7 +121,7 @@ public abstract class AbstractCUDRequestFactory implements CommonCUDRequestFacto
@Override
public ODataPropertyUpdateRequest getPropertyComplexValueUpdateRequest(
final URI targetURI, final UpdateType type, final CommonODataProperty property) {
final URI targetURI, final UT type, final CommonODataProperty property) {
if (!property.hasComplexValue()) {
throw new IllegalArgumentException("A complex value is required");
@ -162,27 +159,6 @@ public abstract class AbstractCUDRequestFactory implements CommonCUDRequestFacto
return req;
}
@Override
public ODataLinkCreateRequest getLinkCreateRequest(final URI targetURI, final ODataLink link) {
return new ODataLinkCreateRequestImpl(client, targetURI, link);
}
@Override
public ODataLinkUpdateRequest getLinkUpdateRequest(
final URI targetURI, final UpdateType type, final ODataLink link) {
final ODataLinkUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataLinkUpdateRequestImpl(client, HttpMethod.POST, targetURI, link);
req.setXHTTPMethod(type.getMethod().name());
} else {
req = new ODataLinkUpdateRequestImpl(client, type.getMethod(), targetURI, link);
}
return req;
}
@Override
public ODataDeleteRequest getDeleteRequest(final URI targetURI) {
final ODataDeleteRequest req;

View File

@ -56,7 +56,7 @@ public class ODataEntityUpdateRequestImpl extends AbstractODataBasicRequest<ODat
* @param uri URI of the entity to be updated.
* @param changes changes to be applied.
*/
ODataEntityUpdateRequestImpl(final CommonODataClient odataClient,
public ODataEntityUpdateRequestImpl(final CommonODataClient odataClient,
final HttpMethod method, final URI uri, final CommonODataEntity changes) {
super(odataClient, ODataPubFormat.class, method, uri);

View File

@ -18,11 +18,17 @@
*/
package org.apache.olingo.client.core.communication.request.cud.v3;
import java.net.URI;
import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkCreateRequest;
import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkUpdateRequest;
import org.apache.olingo.client.api.v3.ODataClient;
import org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.cud.AbstractCUDRequestFactory;
import org.apache.olingo.commons.api.domain.ODataLink;
public class CUDRequestFactoryImpl extends AbstractCUDRequestFactory
public class CUDRequestFactoryImpl extends AbstractCUDRequestFactory<UpdateType>
implements CUDRequestFactory {
private static final long serialVersionUID = 109196636064983035L;
@ -30,4 +36,24 @@ public class CUDRequestFactoryImpl extends AbstractCUDRequestFactory
public CUDRequestFactoryImpl(final ODataClient client) {
super(client);
}
@Override
public ODataLinkCreateRequest getLinkCreateRequest(final URI targetURI, final ODataLink link) {
return new ODataLinkCreateRequestImpl(client, targetURI, link);
}
@Override
public ODataLinkUpdateRequest getLinkUpdateRequest(final URI targetURI, final UpdateType type, final ODataLink link) {
final ODataLinkUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataLinkUpdateRequestImpl(client, HttpMethod.POST, targetURI, link);
req.setXHTTPMethod(type.getMethod().name());
} else {
req = new ODataLinkUpdateRequestImpl(client, type.getMethod(), targetURI, link);
}
return req;
}
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.core.communication.request.cud;
package org.apache.olingo.client.core.communication.request.cud.v3;
import java.io.InputStream;
import java.net.URI;
@ -26,7 +26,7 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataLinkCreateRequest;
import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkCreateRequest;
import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.format.ODataFormat;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.core.communication.request.cud;
package org.apache.olingo.client.core.communication.request.cud.v3;
import java.io.InputStream;
import java.net.URI;
@ -26,7 +26,7 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataLinkUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkUpdateRequest;
import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.format.ODataFormat;

View File

@ -18,11 +18,15 @@
*/
package org.apache.olingo.client.core.communication.request.cud.v4;
import java.net.URI;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
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.ODataEntity;
public class CUDRequestFactoryImpl extends AbstractCUDRequestFactory
public class CUDRequestFactoryImpl extends AbstractCUDRequestFactory<UpdateType>
implements CUDRequestFactory {
private static final long serialVersionUID = 3080623853913380425L;
@ -30,4 +34,13 @@ public class CUDRequestFactoryImpl extends AbstractCUDRequestFactory
public CUDRequestFactoryImpl(final ODataClient client) {
super(client);
}
@Override
public ODataEntityUpdateRequest getEntityUpsertRequest(
final UpdateType type, final URI uri, final ODataEntity entity) {
entity.setEditLink(uri);
return super.getEntityUpdateRequest(type, entity);
}
}

View File

@ -24,6 +24,7 @@ import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataHeaders;
import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
import org.apache.olingo.client.api.communication.request.invoke.v3.InvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.v3.RetrieveRequestFactory;
import org.apache.olingo.client.api.communication.request.streamed.v3.StreamedRequestFactory;
@ -50,7 +51,7 @@ import org.apache.olingo.commons.api.domain.v3.ODataObjectFactory;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.domain.v3.ODataObjectFactoryImpl;
public class ODataClientImpl extends AbstractODataClient implements ODataClient {
public class ODataClientImpl extends AbstractODataClient<UpdateType> implements ODataClient {
private static final long serialVersionUID = -1655712193243609209L;
@ -137,6 +138,7 @@ public class ODataClientImpl extends AbstractODataClient implements ODataClient
return retrieveReqFact;
}
@SuppressWarnings("unchecked")
@Override
public CUDRequestFactory getCUDRequestFactory() {
return cudReqFact;

View File

@ -24,6 +24,7 @@ import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataHeaders;
import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory;
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.api.communication.request.invoke.v4.InvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.v4.RetrieveRequestFactory;
import org.apache.olingo.client.api.communication.request.streamed.v4.StreamedRequestFactory;
@ -50,7 +51,7 @@ import org.apache.olingo.commons.api.domain.v4.ODataObjectFactory;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.domain.v4.ODataObjectFactoryImpl;
public class ODataClientImpl extends AbstractODataClient implements ODataClient {
public class ODataClientImpl extends AbstractODataClient<UpdateType> implements ODataClient {
private static final long serialVersionUID = -6653176125573631964L;
@ -136,6 +137,7 @@ public class ODataClientImpl extends AbstractODataClient implements ODataClient
return retrieveReqFact;
}
@SuppressWarnings("unchecked")
@Override
public CUDRequestFactory getCUDRequestFactory() {
return cudReqFact;

View File

@ -42,7 +42,7 @@ import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.UpdateType;
import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;

View File

@ -22,12 +22,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.net.URI;
import java.util.Collections;
import java.util.List;
import org.apache.olingo.client.api.communication.request.cud.ODataLinkCreateRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataLinkUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkCreateRequest;
import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
import org.apache.olingo.client.api.communication.request.retrieve.v3.ODataLinkCollectionRequest;
import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;

View File

@ -0,0 +1,82 @@
/*
* 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.client.core.it.v4;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.net.URI;
import java.util.Calendar;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.junit.Test;
public class EntityUpdateTestITCase extends AbstractTestITCase {
private void upsert(final UpdateType updateType, final ODataPubFormat format) {
final ODataEntity order = getClient().getObjectFactory().
newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Order"));
order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderID",
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(9)));
order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).build()));
order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build()));
final URI upsertURI = getClient().getURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Orders").appendKeySegment(9).build();
final ODataEntityUpdateRequest req = getClient().getCUDRequestFactory().
getEntityUpsertRequest(updateType, upsertURI, order);
req.setFormat(format);
final ODataEntityUpdateResponse res = req.execute();
try {
final ODataEntity read = read(format, upsertURI);
assertNotNull(read);
assertEquals(order.getProperty("OrderID"), read.getProperty("OrderID"));
assertEquals(order.getProperty("OrderDate").getPrimitiveValue().toString(),
read.getProperty("OrderDate").getPrimitiveValue().toString());
assertEquals(order.getProperty("ShelfLife").getPrimitiveValue().toString(),
read.getProperty("ShelfLife").getPrimitiveValue().toString());
} finally {
getClient().getCUDRequestFactory().getDeleteRequest(upsertURI).execute();
}
}
@Test
public void atomUpsert() {
upsert(UpdateType.PATCH, ODataPubFormat.ATOM);
upsert(UpdateType.REPLACE, ODataPubFormat.ATOM);
}
@Test
public void jsonUpsert() {
upsert(UpdateType.PATCH, ODataPubFormat.JSON);
upsert(UpdateType.REPLACE, ODataPubFormat.JSON);
}
}

View File

@ -144,12 +144,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
} else if (returnType.isAssignableFrom(Date.class)) {
return returnType.cast(dateTimeValue.getTime()); // may throw IllegalArgumentException
} else if (returnType.isAssignableFrom(Timestamp.class)) {
final Timestamp timestamp = new Timestamp(dateTimeValue.getTimeInMillis()); // may throw IllegalArgumentException
if (dateTimeValue.get(Calendar.MILLISECOND) > 0) {
timestamp.setNanos(dateTimeValue.get(Calendar.MILLISECOND)); // may throw IllegalArgumentException
}
return returnType.cast(timestamp);
return returnType.cast(new Timestamp(dateTimeValue.getTimeInMillis()));
} else {
throw new ClassCastException("unsupported return type " + returnType.getSimpleName());
}