[OLINGO-353] fix
This commit is contained in:
parent
13d8d36f9b
commit
ca5ed6e882
|
@ -58,7 +58,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
|
|||
|
||||
private static final long serialVersionUID = 2629912294765040037L;
|
||||
|
||||
private final URI entityURI;
|
||||
protected URI entityURI;
|
||||
|
||||
protected final Map<String, Object> propertyChanges = new HashMap<String, Object>();
|
||||
|
||||
|
@ -131,6 +131,11 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
|
|||
getUUID().getType(),
|
||||
CoreUtils.getKey(getClient(), this, typeRef, entity));
|
||||
|
||||
// fix for OLINGO-353
|
||||
if (this.entityURI == null) {
|
||||
this.entityURI = entity.getEditLink();
|
||||
}
|
||||
|
||||
this.streamedPropertyChanges.clear();
|
||||
this.propertyChanges.clear();
|
||||
this.linkChanges.clear();
|
||||
|
@ -321,7 +326,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
|
|||
&& contentSource != null) {
|
||||
|
||||
final ODataMediaRequest retrieveReq = getClient().getRetrieveRequestFactory()
|
||||
.getMediaEntityRequest(contentSource);
|
||||
.getMediaEntityRequest(contentSource);
|
||||
if (StringUtils.isNotBlank(getEntity().getMediaContentType())) {
|
||||
retrieveReq.setFormat(ODataFormat.fromString(getEntity().getMediaContentType()));
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -47,18 +47,16 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
@Service
|
||||
@Path("/V30/KeyAsSegment.svc")
|
||||
public class V3KeyAsSegment {
|
||||
|
||||
private final V3Services services;
|
||||
public class V3KeyAsSegment extends V3Services {
|
||||
|
||||
public V3KeyAsSegment() throws Exception {
|
||||
services = new V3Services();
|
||||
super();
|
||||
}
|
||||
|
||||
private Response replaceServiceName(final Response response) {
|
||||
try {
|
||||
final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING).
|
||||
replaceAll("Static\\.svc", "KeyAsSegment.svc");
|
||||
replaceAll("Static\\.svc", "KeyAsSegment.svc");
|
||||
|
||||
final Response.ResponseBuilder builder = Response.status(response.getStatus());
|
||||
for (String headerName : response.getHeaders().keySet()) {
|
||||
|
@ -83,93 +81,98 @@ public class V3KeyAsSegment {
|
|||
|
||||
@GET
|
||||
@Path("/{entitySetName}/{entityId}")
|
||||
@Override
|
||||
public Response getEntity(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
|
||||
@QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
|
||||
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
|
||||
@QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
|
||||
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
|
||||
|
||||
return replaceServiceName(services.getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
|
||||
accept, entitySetName, entityId, format, expand, select, true));
|
||||
return replaceServiceName(super.getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
|
||||
accept, entitySetName, entityId, format, expand, select));
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{entitySetName}/{entityId}")
|
||||
@Override
|
||||
public Response removeEntity(
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId) {
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId) {
|
||||
|
||||
return replaceServiceName(services.removeEntity(entitySetName, entityId));
|
||||
return replaceServiceName(super.removeEntity(entitySetName, entityId));
|
||||
}
|
||||
|
||||
@MERGE
|
||||
@Path("/{entitySetName}/{entityId}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Override
|
||||
public Response mergeEntity(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String changes) {
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String changes) {
|
||||
|
||||
return replaceServiceName(services.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName,
|
||||
entityId, changes));
|
||||
return replaceServiceName(super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName,
|
||||
entityId, changes));
|
||||
}
|
||||
|
||||
@PATCH
|
||||
@Path("/{entitySetName}/{entityId}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Override
|
||||
public Response patchEntity(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String changes) {
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String changes) {
|
||||
|
||||
return replaceServiceName(services.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName,
|
||||
entityId, changes));
|
||||
return replaceServiceName(super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName,
|
||||
entityId, changes));
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{entitySetName}/{entityId}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
public Response putNewEntity(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String entity) {
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String entity) {
|
||||
|
||||
return replaceServiceName(services.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId,
|
||||
entity));
|
||||
return replaceServiceName(super.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId,
|
||||
entity));
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{entitySetName}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
|
||||
@Override
|
||||
public Response postNewEntity(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
final String entity) {
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
final String entity) {
|
||||
|
||||
return replaceServiceName(services.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
|
||||
return replaceServiceName(super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ public class V3OpenType extends V3Services {
|
|||
final Matcher matcher = GUID.matcher(entityId);
|
||||
return replaceServiceName(super.getEntityInternal(
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, entitySetName,
|
||||
matcher.matches() ? matcher.group(1) : entityId, format, expand, select, false));
|
||||
matcher.matches() ? matcher.group(1) : entityId, format, expand, select));
|
||||
}
|
||||
|
||||
@POST
|
||||
|
|
|
@ -213,7 +213,7 @@ public class V3Services extends AbstractServices {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Path("/Car/{type:.*}")
|
||||
@Path("/Car/{type:[a-zA-Z].*}")
|
||||
public Response filterCar(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
|
@ -239,7 +239,7 @@ public class V3Services extends AbstractServices {
|
|||
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
|
||||
|
||||
return super.getEntityInternal(uriInfo.getRequestUri().toASCIIString(), accept,
|
||||
"Login", StringUtils.remove(entityId, "'"), format, expand, select, false);
|
||||
"Login", StringUtils.remove(entityId, "'"), format, expand, select);
|
||||
}
|
||||
|
||||
@POST
|
||||
|
|
|
@ -106,7 +106,7 @@ public class V4Demo extends V4Services {
|
|||
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
|
||||
|
||||
return replaceServiceName(super.getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
|
||||
accept, entitySetName, entityId, format, expand, select, false));
|
||||
accept, entitySetName, entityId, format, expand, select));
|
||||
}
|
||||
|
||||
@GET
|
||||
|
|
|
@ -25,12 +25,14 @@ import java.io.InputStream;
|
|||
import javax.ws.rs.Consumes;
|
||||
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 javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -46,9 +48,6 @@ import org.springframework.stereotype.Service;
|
|||
@Path("/V40/KeyAsSegment.svc")
|
||||
public class V4KeyAsSegment extends V4Services {
|
||||
|
||||
@Context
|
||||
private UriInfo uriInfo;
|
||||
|
||||
public V4KeyAsSegment() throws Exception {
|
||||
super();
|
||||
}
|
||||
|
@ -56,7 +55,7 @@ public class V4KeyAsSegment extends V4Services {
|
|||
private Response replaceServiceName(final Response response) {
|
||||
try {
|
||||
final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING).
|
||||
replaceAll("Static\\.svc", "KeyAsSegment.svc");
|
||||
replaceAll("Static\\.svc", "KeyAsSegment.svc");
|
||||
|
||||
final Response.ResponseBuilder builder = Response.status(response.getStatus());
|
||||
for (String headerName : response.getHeaders().keySet()) {
|
||||
|
@ -79,70 +78,80 @@ public class V4KeyAsSegment extends V4Services {
|
|||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{entitySetName}/{entityId}")
|
||||
@Override
|
||||
public Response getEntitySet(final String accept, final String name, final String type) {
|
||||
public Response getEntity(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
|
||||
@QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
|
||||
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
|
||||
|
||||
return replaceServiceName(super.getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
|
||||
accept, name, type, null, null, null, true));
|
||||
accept, entitySetName, entityId, format, expand, select));
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{entitySetName}/{entityId}")
|
||||
@Override
|
||||
public Response removeEntity(
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId) {
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId) {
|
||||
|
||||
return replaceServiceName(super.removeEntity(entitySetName, entityId));
|
||||
}
|
||||
|
||||
@PATCH
|
||||
@Path("/{entitySetName}/{entityId}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Override
|
||||
public Response patchEntity(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String changes) {
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String changes) {
|
||||
|
||||
return replaceServiceName(super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId,
|
||||
changes));
|
||||
changes));
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{entitySetName}/{entityId}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
public Response putNewEntity(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String entity) {
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
@PathParam("entityId") final String entityId,
|
||||
final String entity) {
|
||||
|
||||
return replaceServiceName(super
|
||||
.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity));
|
||||
.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity));
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{entitySetName}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
|
||||
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
|
||||
@Override
|
||||
public Response postNewEntity(
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
final String entity) {
|
||||
@Context final UriInfo uriInfo,
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
final String entity) {
|
||||
|
||||
return replaceServiceName(super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public class V4OpenType extends V4Services {
|
|||
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
|
||||
|
||||
return replaceServiceName(super.getEntityInternal(
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, entitySetName, entityId, format, expand, select, false));
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, entitySetName, entityId, format, expand, select));
|
||||
}
|
||||
|
||||
@POST
|
||||
|
|
|
@ -371,7 +371,7 @@ public class V4Services extends AbstractServices {
|
|||
return StringUtils.isBlank(filter) && StringUtils.isBlank(search)
|
||||
? NumberUtils.isNumber(type)
|
||||
? super.getEntityInternal(
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "People", type, format, null, null, true)
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "People", type, format, null, null)
|
||||
: super.getEntitySet(accept, "People", type)
|
||||
: super.getEntitySet(uriInfo, accept, "People", top, skip, format, count, filter, orderby, skiptoken);
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ public class V4Services extends AbstractServices {
|
|||
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
|
||||
|
||||
return getEntityInternal(
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Boss", StringUtils.EMPTY, format, null, null, false);
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Boss", StringUtils.EMPTY, format, null, null);
|
||||
}
|
||||
|
||||
@GET
|
||||
|
@ -395,7 +395,7 @@ public class V4Services extends AbstractServices {
|
|||
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
|
||||
|
||||
return getEntityInternal(
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Company", StringUtils.EMPTY, format, null, null, false);
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Company", StringUtils.EMPTY, format, null, null);
|
||||
}
|
||||
|
||||
@PATCH
|
||||
|
@ -626,7 +626,7 @@ public class V4Services extends AbstractServices {
|
|||
assert entry.getProperty("index") != null;
|
||||
|
||||
return getEntityInternal(
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Customers", personId, format, null, null, false);
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Customers", personId, format, null, null);
|
||||
} catch (Exception e) {
|
||||
return xml.createFaultResponse(accept, e);
|
||||
}
|
||||
|
@ -642,7 +642,7 @@ public class V4Services extends AbstractServices {
|
|||
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
|
||||
|
||||
return getEntityInternal(
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Products", productId, format, null, null, false);
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Products", productId, format, null, null);
|
||||
}
|
||||
|
||||
@POST
|
||||
|
@ -767,7 +767,7 @@ public class V4Services extends AbstractServices {
|
|||
|
||||
final Response response =
|
||||
getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
|
||||
accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
|
||||
accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY);
|
||||
return response.getStatus() >= 400
|
||||
? postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes)
|
||||
: super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
|
||||
|
@ -785,7 +785,7 @@ public class V4Services extends AbstractServices {
|
|||
|
||||
try {
|
||||
getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
|
||||
accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
|
||||
accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY);
|
||||
return super.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity);
|
||||
} catch (NotFoundException e) {
|
||||
return postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId);
|
||||
|
@ -1117,7 +1117,7 @@ public class V4Services extends AbstractServices {
|
|||
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
|
||||
|
||||
return getEntityInternal(
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "1", format, null, null, false);
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "1", format, null, null);
|
||||
}
|
||||
|
||||
@GET
|
||||
|
@ -1128,7 +1128,7 @@ public class V4Services extends AbstractServices {
|
|||
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
|
||||
|
||||
return getEntityInternal(
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "1", format, null, null, false);
|
||||
uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "1", format, null, null);
|
||||
}
|
||||
|
||||
@GET
|
||||
|
|
|
@ -38,7 +38,6 @@ import java.util.regex.Pattern;
|
|||
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -88,11 +87,17 @@ public abstract class AbstractUtilities {
|
|||
public static final String BOUNDARY = "boundary";
|
||||
|
||||
protected final ODataServiceVersion version;
|
||||
|
||||
protected final Metadata metadata;
|
||||
|
||||
protected final FSManager fsManager;
|
||||
|
||||
protected final ODataDeserializer atomDeserializer;
|
||||
|
||||
protected final ODataDeserializer jsonDeserializer;
|
||||
|
||||
protected final ODataSerializer atomSerializer;
|
||||
|
||||
protected final ODataSerializer jsonSerializer;
|
||||
|
||||
public AbstractUtilities(final ODataServiceVersion version, final Metadata metadata) throws Exception {
|
||||
|
@ -111,7 +116,7 @@ public abstract class AbstractUtilities {
|
|||
|
||||
/**
|
||||
* Add links to the given entity.
|
||||
*
|
||||
*
|
||||
* @param entitySetName
|
||||
* @param entitykey
|
||||
* @param is
|
||||
|
@ -119,12 +124,12 @@ public abstract class AbstractUtilities {
|
|||
* @return
|
||||
*/
|
||||
protected abstract InputStream addLinks(
|
||||
final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
|
||||
throws Exception;
|
||||
final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Retrieve all entity link names.
|
||||
*
|
||||
*
|
||||
* @param is
|
||||
* @return
|
||||
* @throws IOException
|
||||
|
@ -134,17 +139,17 @@ public abstract class AbstractUtilities {
|
|||
|
||||
/**
|
||||
* Retrieve entity links and inlines.
|
||||
*
|
||||
*
|
||||
* @param entitySetName
|
||||
* @param is
|
||||
* @return
|
||||
*/
|
||||
protected abstract NavigationLinks retrieveNavigationInfo(final String entitySetName, final InputStream is)
|
||||
throws Exception;
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Normalize navigation info and add edit link if missing.
|
||||
*
|
||||
*
|
||||
* @param entitySetName
|
||||
* @param entityKey
|
||||
* @param is
|
||||
|
@ -152,28 +157,20 @@ public abstract class AbstractUtilities {
|
|||
* @return
|
||||
*/
|
||||
protected abstract InputStream normalizeLinks(
|
||||
final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
|
||||
throws Exception;
|
||||
final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
|
||||
throws Exception;
|
||||
|
||||
public InputStream saveSingleEntity(
|
||||
final String key,
|
||||
final String entitySetName,
|
||||
final InputStream is) throws Exception {
|
||||
|
||||
return saveSingleEntity(key, entitySetName, is, null);
|
||||
}
|
||||
|
||||
public InputStream saveSingleEntity(
|
||||
final String key,
|
||||
final String entitySetName,
|
||||
final InputStream is,
|
||||
final NavigationLinks links) throws Exception {
|
||||
final String key,
|
||||
final String entitySetName,
|
||||
final InputStream is,
|
||||
final NavigationLinks links) throws Exception {
|
||||
|
||||
// -----------------------------------------
|
||||
// 0. Get the path
|
||||
// -----------------------------------------
|
||||
final String path =
|
||||
entitySetName + File.separatorChar + Commons.getEntityKey(key) + File.separatorChar
|
||||
entitySetName + File.separatorChar + Commons.getEntityKey(key) + File.separatorChar
|
||||
+ Constants.get(version, ConstantKey.ENTITY);
|
||||
// -----------------------------------------
|
||||
|
||||
|
@ -200,10 +197,10 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public InputStream addOrReplaceEntity(
|
||||
final String key,
|
||||
final String entitySetName,
|
||||
final InputStream is,
|
||||
final Entity entry) throws Exception {
|
||||
final String key,
|
||||
final String entitySetName,
|
||||
final InputStream is,
|
||||
final Entity entry) throws Exception {
|
||||
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
IOUtils.copy(is, bos);
|
||||
|
@ -218,7 +215,7 @@ public abstract class AbstractUtilities {
|
|||
try {
|
||||
linksToBeKept = new HashSet<String>(navigationProperties.keySet());
|
||||
} catch (NullPointerException e) {
|
||||
linksToBeKept = Collections.<String> emptySet();
|
||||
linksToBeKept = Collections.<String>emptySet();
|
||||
}
|
||||
|
||||
for (String availableLink : new HashSet<String>(linksToBeKept)) {
|
||||
|
@ -251,8 +248,8 @@ public abstract class AbstractUtilities {
|
|||
// -----------------------------------------
|
||||
// 3. Normalize navigation info; add edit link; ... and save entity ....
|
||||
// -----------------------------------------
|
||||
final InputStream createdEntity =
|
||||
saveSingleEntity(entityKey, entitySetName, new ByteArrayInputStream(bos.toByteArray()), links);
|
||||
final InputStream createdEntity = saveSingleEntity(
|
||||
entityKey, entitySetName, new ByteArrayInputStream(bos.toByteArray()), links);
|
||||
// -----------------------------------------
|
||||
|
||||
bos.reset();
|
||||
|
@ -262,7 +259,7 @@ public abstract class AbstractUtilities {
|
|||
// 4. Add navigation links to be kept
|
||||
// -----------------------------------------
|
||||
final InputStream normalizedEntity =
|
||||
addLinks(entitySetName, entityKey, new ByteArrayInputStream(bos.toByteArray()), linksToBeKept);
|
||||
addLinks(entitySetName, entityKey, new ByteArrayInputStream(bos.toByteArray()), linksToBeKept);
|
||||
// -----------------------------------------
|
||||
|
||||
IOUtils.closeQuietly(bos);
|
||||
|
@ -271,8 +268,8 @@ public abstract class AbstractUtilities {
|
|||
// 5. save the entity
|
||||
// -----------------------------------------
|
||||
final FileObject fo = fsManager.putInMemory(
|
||||
normalizedEntity,
|
||||
fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), getDefaultFormat()));
|
||||
normalizedEntity,
|
||||
fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), getDefaultFormat()));
|
||||
// -----------------------------------------
|
||||
|
||||
// -----------------------------------------
|
||||
|
@ -286,17 +283,17 @@ public abstract class AbstractUtilities {
|
|||
|
||||
for (final Link link : entry.getNavigationLinks()) {
|
||||
final NavigationProperty navProp =
|
||||
navigationProperties == null ? null : navigationProperties.get(link.getTitle());
|
||||
navigationProperties == null ? null : navigationProperties.get(link.getTitle());
|
||||
if (navProp != null) {
|
||||
final String inlineEntitySetName = navProp.getTarget();
|
||||
if (link.getInlineEntity() != null) {
|
||||
final String inlineEntryKey = getDefaultEntryKey(inlineEntitySetName, link.getInlineEntity());
|
||||
|
||||
addOrReplaceEntity(
|
||||
inlineEntryKey,
|
||||
inlineEntitySetName,
|
||||
toInputStream(link.getInlineEntity()),
|
||||
link.getInlineEntity());
|
||||
inlineEntryKey,
|
||||
inlineEntitySetName,
|
||||
toInputStream(link.getInlineEntity()),
|
||||
link.getInlineEntity());
|
||||
|
||||
hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")");
|
||||
} else if (link.getInlineEntitySet() != null) {
|
||||
|
@ -304,10 +301,10 @@ public abstract class AbstractUtilities {
|
|||
final String inlineEntryKey = getDefaultEntryKey(inlineEntitySetName, subentry);
|
||||
|
||||
addOrReplaceEntity(
|
||||
inlineEntryKey,
|
||||
inlineEntitySetName,
|
||||
toInputStream(subentry),
|
||||
subentry);
|
||||
inlineEntryKey,
|
||||
inlineEntitySetName,
|
||||
toInputStream(subentry),
|
||||
subentry);
|
||||
|
||||
hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")");
|
||||
}
|
||||
|
@ -324,9 +321,9 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public void addMediaEntityValue(
|
||||
final String entitySetName,
|
||||
final String entityKey,
|
||||
final InputStream is) throws Exception {
|
||||
final String entitySetName,
|
||||
final String entityKey,
|
||||
final InputStream is) throws Exception {
|
||||
|
||||
// -----------------------------------------
|
||||
// 0. Get default entry key and path (N.B. operation will consume/close the stream; use a copy instead)
|
||||
|
@ -338,17 +335,17 @@ public abstract class AbstractUtilities {
|
|||
// 1. save the media entity value
|
||||
// -----------------------------------------
|
||||
fsManager.putInMemory(is, fsManager.getAbsolutePath(path
|
||||
+ Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME), null));
|
||||
+ Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME), null));
|
||||
IOUtils.closeQuietly(is);
|
||||
// -----------------------------------------
|
||||
}
|
||||
|
||||
public void putLinksInMemory(
|
||||
final String basePath,
|
||||
final String entitySetName,
|
||||
final String entityKey,
|
||||
final String linkName,
|
||||
final Collection<String> links) throws Exception {
|
||||
final String basePath,
|
||||
final String entitySetName,
|
||||
final String entityKey,
|
||||
final String linkName,
|
||||
final Collection<String> links) throws Exception {
|
||||
|
||||
final HashSet<String> uris = new HashSet<String>();
|
||||
|
||||
|
@ -359,7 +356,8 @@ public abstract class AbstractUtilities {
|
|||
try {
|
||||
final Map.Entry<String, List<String>> currents = extractLinkURIs(entitySetName, entityKey, linkName);
|
||||
uris.addAll(currents.getValue());
|
||||
} catch (Exception ignore) {}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
uris.addAll(links);
|
||||
|
@ -368,20 +366,20 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public void putLinksInMemory(
|
||||
final String basePath, final String entitySetName, final String linkName, final Collection<String> uris)
|
||||
throws Exception {
|
||||
final String basePath, final String entitySetName, final String linkName, final Collection<String> uris)
|
||||
throws Exception {
|
||||
|
||||
fsManager.putInMemory(
|
||||
Commons.getLinksAsJSON(version, entitySetName, new SimpleEntry<String, Collection<String>>(linkName, uris)),
|
||||
Commons.getLinksPath(version, basePath, linkName, Accept.JSON_FULLMETA));
|
||||
Commons.getLinksAsJSON(version, entitySetName, new SimpleEntry<String, Collection<String>>(linkName, uris)),
|
||||
Commons.getLinksPath(version, basePath, linkName, Accept.JSON_FULLMETA));
|
||||
|
||||
fsManager.putInMemory(
|
||||
Commons.getLinksAsATOM(version, new SimpleEntry<String, Collection<String>>(linkName, uris)),
|
||||
Commons.getLinksPath(version, basePath, linkName, Accept.XML));
|
||||
Commons.getLinksAsATOM(version, new SimpleEntry<String, Collection<String>>(linkName, uris)),
|
||||
Commons.getLinksPath(version, basePath, linkName, Accept.XML));
|
||||
}
|
||||
|
||||
public Response createResponse(
|
||||
final String location, final InputStream entity, final String etag, final Accept accept) {
|
||||
final String location, final InputStream entity, final String etag, final Accept accept) {
|
||||
return createResponse(location, entity, etag, accept, null);
|
||||
}
|
||||
|
||||
|
@ -416,26 +414,26 @@ public abstract class AbstractUtilities {
|
|||
|
||||
public Response createBatchResponse(final InputStream stream) {
|
||||
final Response.ResponseBuilder builder = version.compareTo(ODataServiceVersion.V30) <= 0
|
||||
? Response.accepted(stream)
|
||||
: Response.ok(stream);
|
||||
? Response.accepted(stream)
|
||||
: Response.ok(stream);
|
||||
builder.header(Constants.get(version, ConstantKey.ODATA_SERVICE_VERSION), version.toString() + ";");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public Response createResponse(
|
||||
final InputStream entity,
|
||||
final String etag,
|
||||
final Accept accept,
|
||||
final Response.Status status) {
|
||||
final InputStream entity,
|
||||
final String etag,
|
||||
final Accept accept,
|
||||
final Response.Status status) {
|
||||
return createResponse(null, entity, etag, accept, status);
|
||||
}
|
||||
|
||||
public Response createResponse(
|
||||
final String location,
|
||||
final InputStream entity,
|
||||
final String etag,
|
||||
final Accept accept,
|
||||
final Response.Status status) {
|
||||
final String location,
|
||||
final InputStream entity,
|
||||
final String etag,
|
||||
final Accept accept,
|
||||
final Response.Status status) {
|
||||
|
||||
final Response.ResponseBuilder builder = Response.ok();
|
||||
if (version.compareTo(ODataServiceVersion.V30) <= 0) {
|
||||
|
@ -530,14 +528,14 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public EntitySet readEntitySet(final Accept accept, final InputStream entitySet)
|
||||
throws ODataDeserializerException {
|
||||
return (accept == Accept.ATOM || accept == Accept.XML ?
|
||||
atomDeserializer.toEntitySet(entitySet) : jsonDeserializer.toEntitySet(entitySet))
|
||||
.getPayload();
|
||||
throws ODataDeserializerException {
|
||||
return (accept == Accept.ATOM || accept == Accept.XML ? atomDeserializer.toEntitySet(entitySet) : jsonDeserializer.
|
||||
toEntitySet(entitySet))
|
||||
.getPayload();
|
||||
}
|
||||
|
||||
public InputStream writeEntitySet(final Accept accept, final ResWrap<EntitySet> container)
|
||||
throws ODataSerializerException, IOException {
|
||||
throws ODataSerializerException, IOException {
|
||||
|
||||
final StringWriter writer = new StringWriter();
|
||||
if (accept == Accept.ATOM || accept == Accept.XML) {
|
||||
|
@ -552,18 +550,18 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public ResWrap<Entity> readContainerEntity(final Accept accept, final InputStream entity)
|
||||
throws ODataDeserializerException {
|
||||
return accept == Accept.ATOM || accept == Accept.XML ?
|
||||
atomDeserializer.toEntity(entity) : jsonDeserializer.toEntity(entity);
|
||||
throws ODataDeserializerException {
|
||||
return accept == Accept.ATOM || accept == Accept.XML ? atomDeserializer.toEntity(entity) : jsonDeserializer.
|
||||
toEntity(entity);
|
||||
}
|
||||
|
||||
public Entity readEntity(final Accept accept, final InputStream entity)
|
||||
throws IOException, ODataDeserializerException {
|
||||
throws IOException, ODataDeserializerException {
|
||||
return readContainerEntity(accept, entity).getPayload();
|
||||
}
|
||||
|
||||
public InputStream writeEntity(final Accept accept, final ResWrap<Entity> container)
|
||||
throws ODataSerializerException {
|
||||
throws ODataSerializerException {
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
if (accept == Accept.ATOM || accept == Accept.XML) {
|
||||
|
@ -576,7 +574,7 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public InputStream writeProperty(final Accept accept, final Property property)
|
||||
throws ODataSerializerException {
|
||||
throws ODataSerializerException {
|
||||
|
||||
final StringWriter writer = new StringWriter();
|
||||
if (accept == Accept.XML || accept == Accept.ATOM) {
|
||||
|
@ -589,13 +587,13 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public Property readProperty(final Accept accept, final InputStream property) throws ODataDeserializerException {
|
||||
return (Accept.ATOM == accept || Accept.XML == accept ?
|
||||
atomDeserializer.toProperty(property) : jsonDeserializer.toProperty(property))
|
||||
.getPayload();
|
||||
return (Accept.ATOM == accept || Accept.XML == accept ? atomDeserializer.toProperty(property) : jsonDeserializer.
|
||||
toProperty(property))
|
||||
.getPayload();
|
||||
}
|
||||
|
||||
public InputStream writeProperty(final Accept accept, final ResWrap<Property> container)
|
||||
throws ODataSerializerException {
|
||||
throws ODataSerializerException {
|
||||
|
||||
final StringWriter writer = new StringWriter();
|
||||
if (accept == Accept.XML || accept == Accept.ATOM) {
|
||||
|
@ -608,7 +606,7 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
private String getDefaultEntryKey(final String entitySetName, final Entity entry, final String propertyName)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
|
||||
String res;
|
||||
if (entry.getProperty(propertyName) == null) {
|
||||
|
@ -641,7 +639,7 @@ public abstract class AbstractUtilities {
|
|||
} else {
|
||||
productID = (Integer) entity.getProperty("OrderID").asPrimitive();
|
||||
res = "OrderID=" + entity.getProperty("OrderID").asPrimitive()
|
||||
+ ",ProductID=" + entity.getProperty("ProductID").asPrimitive();
|
||||
+ ",ProductID=" + entity.getProperty("ProductID").asPrimitive();
|
||||
}
|
||||
Commons.SEQUENCE.put(entitySetName, productID);
|
||||
} else if ("Message".equals(entitySetName)) {
|
||||
|
@ -656,7 +654,7 @@ public abstract class AbstractUtilities {
|
|||
} else {
|
||||
messageId = (Integer) entity.getProperty("MessageId").asPrimitive();
|
||||
res = "FromUsername=" + entity.getProperty("FromUsername").asPrimitive()
|
||||
+ ",MessageId=" + entity.getProperty("MessageId").asPrimitive();
|
||||
+ ",MessageId=" + entity.getProperty("MessageId").asPrimitive();
|
||||
}
|
||||
Commons.SEQUENCE.put(entitySetName, messageId);
|
||||
} else if ("Order".equals(entitySetName)) {
|
||||
|
@ -701,7 +699,7 @@ public abstract class AbstractUtilities {
|
|||
productId = (Integer) entity.getProperty("ProductID").asPrimitive();
|
||||
productDetailId = (Integer) entity.getProperty("ProductDetailID").asPrimitive();
|
||||
res = "ProductID=" + entity.getProperty("ProductID").asPrimitive()
|
||||
+ ",ProductDetailID=" + entity.getProperty("ProductDetailID").asPrimitive();
|
||||
+ ",ProductDetailID=" + entity.getProperty("ProductDetailID").asPrimitive();
|
||||
}
|
||||
Commons.SEQUENCE.put(entitySetName, productDetailId);
|
||||
Commons.SEQUENCE.put("Products", productId);
|
||||
|
@ -723,12 +721,12 @@ public abstract class AbstractUtilities {
|
|||
|
||||
public String getLinksBasePath(final String entitySetName, final String entityId) {
|
||||
return entitySetName + File.separatorChar + Commons.getEntityKey(entityId) + File.separatorChar
|
||||
+ Constants.get(version, ConstantKey.LINKS_FILE_PATH) + File.separatorChar;
|
||||
+ Constants.get(version, ConstantKey.LINKS_FILE_PATH) + File.separatorChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves entity links about the given link name.
|
||||
*
|
||||
*
|
||||
* @param entitySetName entity set name.
|
||||
* @param entityId entity id.
|
||||
* @param linkName link name.
|
||||
|
@ -736,8 +734,8 @@ public abstract class AbstractUtilities {
|
|||
* @return a pair of ETag/links stream
|
||||
*/
|
||||
public LinkInfo readLinks(
|
||||
final String entitySetName, final String entityId, final String linkName, final Accept accept)
|
||||
throws Exception {
|
||||
final String entitySetName, final String entityId, final String linkName, final Accept accept)
|
||||
throws Exception {
|
||||
|
||||
final String basePath = getLinksBasePath(entitySetName, entityId);
|
||||
|
||||
|
@ -751,16 +749,16 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public InputStream putMediaInMemory(
|
||||
final String entitySetName, final String entityId, final InputStream value)
|
||||
throws IOException {
|
||||
final String entitySetName, final String entityId, final InputStream value)
|
||||
throws IOException {
|
||||
return putMediaInMemory(entitySetName, entityId, null, value);
|
||||
}
|
||||
|
||||
public InputStream putMediaInMemory(
|
||||
final String entitySetName, final String entityId, final String name, final InputStream value)
|
||||
throws IOException {
|
||||
final String entitySetName, final String entityId, final String name, final InputStream value)
|
||||
throws IOException {
|
||||
final FileObject fo = fsManager.putInMemory(value, fsManager.getAbsolutePath(
|
||||
Commons.getEntityBasePath(entitySetName, entityId)
|
||||
Commons.getEntityBasePath(entitySetName, entityId)
|
||||
+ (name == null ? Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME) : name), null));
|
||||
|
||||
return fo.getContent().getInputStream();
|
||||
|
@ -771,14 +769,14 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public Map.Entry<String, InputStream> readMediaEntity(
|
||||
final String entitySetName, final String entityId, final String name) {
|
||||
final String entitySetName, final String entityId, final String name) {
|
||||
final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
|
||||
return new SimpleEntry<String, InputStream>(basePath, fsManager.readFile(basePath
|
||||
+ (name == null ? Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME) : name)));
|
||||
+ (name == null ? Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME) : name)));
|
||||
}
|
||||
|
||||
public Map.Entry<String, InputStream> readEntity(
|
||||
final String entitySetName, final String entityId, final Accept accept) {
|
||||
final String entitySetName, final String entityId, final Accept accept) {
|
||||
|
||||
if (accept == Accept.XML || accept == Accept.TEXT) {
|
||||
throw new UnsupportedMediaTypeException("Unsupported media type");
|
||||
|
@ -786,14 +784,14 @@ public abstract class AbstractUtilities {
|
|||
|
||||
final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
|
||||
return new SimpleEntry<String, InputStream>(basePath,
|
||||
fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), accept));
|
||||
fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), accept));
|
||||
}
|
||||
|
||||
public InputStream expandEntity(
|
||||
final String entitySetName,
|
||||
final String entityId,
|
||||
final String linkName)
|
||||
throws Exception {
|
||||
final String entitySetName,
|
||||
final String entityId,
|
||||
final String linkName)
|
||||
throws Exception {
|
||||
|
||||
// --------------------------------
|
||||
// 0. Retrieve all 'linkName' navigation link uris (NotFoundException if missing)
|
||||
|
@ -807,18 +805,18 @@ public abstract class AbstractUtilities {
|
|||
final Map<String, NavigationProperty> navigationProperties = metadata.getNavigationProperties(entitySetName);
|
||||
|
||||
return readEntities(
|
||||
links.getValue(),
|
||||
linkName,
|
||||
links.getKey(),
|
||||
navigationProperties.get(linkName).isEntitySet());
|
||||
links.getValue(),
|
||||
linkName,
|
||||
links.getKey(),
|
||||
navigationProperties.get(linkName).isEntitySet());
|
||||
}
|
||||
|
||||
public InputStream expandEntity(
|
||||
final String entitySetName,
|
||||
final String entityId,
|
||||
final InputStream entity,
|
||||
final String linkName)
|
||||
throws Exception {
|
||||
final String entitySetName,
|
||||
final String entityId,
|
||||
final InputStream entity,
|
||||
final String linkName)
|
||||
throws Exception {
|
||||
// --------------------------------
|
||||
// 2. Retrieve expanded object (entry or feed)
|
||||
// --------------------------------
|
||||
|
@ -827,14 +825,14 @@ public abstract class AbstractUtilities {
|
|||
}
|
||||
|
||||
public InputStream deleteProperty(
|
||||
final String entitySetName,
|
||||
final String entityId,
|
||||
final List<String> path,
|
||||
final Accept accept) throws Exception {
|
||||
final String entitySetName,
|
||||
final String entityId,
|
||||
final List<String> path,
|
||||
final Accept accept) throws Exception {
|
||||
final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
|
||||
|
||||
final Accept acceptType = accept == null || Accept.TEXT == accept
|
||||
? Accept.XML : accept.getExtension().equals(Accept.JSON.getExtension()) ? Accept.JSON_FULLMETA : accept;
|
||||
? Accept.XML : accept.getExtension().equals(Accept.JSON.getExtension()) ? Accept.JSON_FULLMETA : accept;
|
||||
|
||||
// read atom
|
||||
InputStream stream = fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType);
|
||||
|
@ -844,44 +842,44 @@ public abstract class AbstractUtilities {
|
|||
|
||||
// save atom
|
||||
fsManager.putInMemory(stream,
|
||||
fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType));
|
||||
fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType));
|
||||
|
||||
return fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType);
|
||||
}
|
||||
|
||||
public abstract InputStream readEntities(
|
||||
final List<String> links, final String linkName, final String next, final boolean forceFeed)
|
||||
throws Exception;
|
||||
final List<String> links, final String linkName, final String next, final boolean forceFeed)
|
||||
throws Exception;
|
||||
|
||||
protected abstract InputStream replaceLink(
|
||||
final InputStream toBeChanged, final String linkName, final InputStream replacement)
|
||||
throws Exception;
|
||||
final InputStream toBeChanged, final String linkName, final InputStream replacement)
|
||||
throws Exception;
|
||||
|
||||
public abstract InputStream selectEntity(final InputStream entity, final String[] propertyNames)
|
||||
throws Exception;
|
||||
throws Exception;
|
||||
|
||||
protected abstract Accept getDefaultFormat();
|
||||
|
||||
protected abstract Map<String, InputStream> getChanges(final InputStream src) throws Exception;
|
||||
|
||||
public abstract InputStream addEditLink(
|
||||
final InputStream content, final String title, final String href) throws Exception;
|
||||
final InputStream content, final String title, final String href) throws Exception;
|
||||
|
||||
public abstract InputStream addOperation(
|
||||
final InputStream content, final String name, final String metaAnchor, final String href)
|
||||
throws Exception;
|
||||
final InputStream content, final String name, final String metaAnchor, final String href)
|
||||
throws Exception;
|
||||
|
||||
protected abstract InputStream replaceProperty(
|
||||
final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
|
||||
throws Exception;
|
||||
final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
|
||||
throws Exception;
|
||||
|
||||
protected abstract InputStream deleteProperty(final InputStream src, final List<String> path)
|
||||
throws Exception;
|
||||
throws Exception;
|
||||
|
||||
public abstract Map.Entry<String, List<String>> extractLinkURIs(final InputStream is)
|
||||
throws Exception;
|
||||
throws Exception;
|
||||
|
||||
public abstract Map.Entry<String, List<String>> extractLinkURIs(
|
||||
final String entitySetName, final String entityId, final String linkName)
|
||||
throws Exception;
|
||||
final String entitySetName, final String entityId, final String linkName)
|
||||
throws Exception;
|
||||
}
|
||||
|
|
|
@ -56,13 +56,13 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
mapper.setInjectableValues(new InjectableValues.Std()
|
||||
.addValue(Boolean.class, Boolean.TRUE)
|
||||
.addValue(ODataServiceVersion.class, version));
|
||||
.addValue(Boolean.class, Boolean.TRUE)
|
||||
.addValue(ODataServiceVersion.class, version));
|
||||
mapper.setSerializerProvider(new InjectableSerializerProvider(mapper.getSerializerProvider(),
|
||||
mapper.getSerializationConfig()
|
||||
mapper.getSerializationConfig()
|
||||
.withAttribute(ODataServiceVersion.class, version)
|
||||
.withAttribute(Boolean.class, Boolean.TRUE),
|
||||
mapper.getSerializerFactory()));
|
||||
mapper.getSerializerFactory()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,15 +72,15 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
protected InputStream addLinks(
|
||||
final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
|
||||
throws IOException {
|
||||
final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
|
||||
throws IOException {
|
||||
|
||||
final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
|
||||
IOUtils.closeQuietly(is);
|
||||
|
||||
for (String link : links) {
|
||||
srcNode.set(link + Constants.get(version, ConstantKey.JSON_NAVIGATION_SUFFIX),
|
||||
new TextNode(Commons.getLinksURI(entitySetName, entitykey, link)));
|
||||
new TextNode(Commons.getLinksURI(entitySetName, entitykey, link)));
|
||||
}
|
||||
|
||||
return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING);
|
||||
|
@ -99,9 +99,9 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
final String field = fieldIter.next();
|
||||
|
||||
if (field.endsWith(Constants.get(version, ConstantKey.JSON_NAVIGATION_BIND_SUFFIX))
|
||||
|| field.endsWith(Constants.get(version, ConstantKey.JSON_NAVIGATION_SUFFIX))
|
||||
|| field.endsWith(Constants.get(version, ConstantKey.JSON_MEDIA_SUFFIX))
|
||||
|| field.endsWith(Constants.get(version, ConstantKey.JSON_EDITLINK_NAME))) {
|
||||
|| field.endsWith(Constants.get(version, ConstantKey.JSON_NAVIGATION_SUFFIX))
|
||||
|| field.endsWith(Constants.get(version, ConstantKey.JSON_MEDIA_SUFFIX))
|
||||
|| field.endsWith(Constants.get(version, ConstantKey.JSON_EDITLINK_NAME))) {
|
||||
if (field.indexOf('@') > 0) {
|
||||
links.add(field.substring(0, field.indexOf('@')));
|
||||
} else {
|
||||
|
@ -115,7 +115,7 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
protected NavigationLinks retrieveNavigationInfo(final String entitySetName, final InputStream is)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
|
||||
final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
|
||||
IOUtils.closeQuietly(is);
|
||||
|
@ -152,8 +152,8 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
protected InputStream normalizeLinks(
|
||||
final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
|
||||
throws IOException {
|
||||
final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
|
||||
throws IOException {
|
||||
|
||||
final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
|
||||
|
||||
|
@ -162,16 +162,16 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
// normalize link
|
||||
srcNode.remove(linkTitle + Constants.get(version, ConstantKey.JSON_NAVIGATION_BIND_SUFFIX));
|
||||
srcNode.set(
|
||||
linkTitle + Constants.get(version, ConstantKey.JSON_NAVIGATION_SUFFIX),
|
||||
new TextNode(String.format("%s(%s)/%s", entitySetName, entityKey, linkTitle)));
|
||||
linkTitle + Constants.get(version, ConstantKey.JSON_NAVIGATION_SUFFIX),
|
||||
new TextNode(String.format("%s(%s)/%s", entitySetName, entityKey, linkTitle)));
|
||||
}
|
||||
|
||||
for (String linkTitle : links.getInlineNames()) {
|
||||
// normalize link if exist; declare a new one if missing
|
||||
srcNode.remove(linkTitle + Constants.get(version, ConstantKey.JSON_NAVIGATION_BIND_SUFFIX));
|
||||
srcNode.set(
|
||||
linkTitle + Constants.get(version, ConstantKey.JSON_NAVIGATION_SUFFIX),
|
||||
new TextNode(String.format("%s(%s)/%s", entitySetName, entityKey, linkTitle)));
|
||||
linkTitle + Constants.get(version, ConstantKey.JSON_NAVIGATION_SUFFIX),
|
||||
new TextNode(String.format("%s(%s)/%s", entitySetName, entityKey, linkTitle)));
|
||||
|
||||
// remove inline
|
||||
srcNode.remove(linkTitle);
|
||||
|
@ -182,7 +182,7 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
}
|
||||
|
||||
srcNode.set(
|
||||
Constants.get(version, ConstantKey.JSON_EDITLINK_NAME), new TextNode(
|
||||
Constants.get(version, ConstantKey.JSON_EDITLINK_NAME), new TextNode(
|
||||
Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL) + entitySetName + "(" + entityKey + ")"));
|
||||
|
||||
return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING);
|
||||
|
@ -258,8 +258,8 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public InputStream readEntities(
|
||||
final List<String> links, final String linkName, final String next, final boolean forceFeed)
|
||||
throws IOException {
|
||||
final List<String> links, final String linkName, final String next, final boolean forceFeed)
|
||||
throws IOException {
|
||||
|
||||
if (links.isEmpty()) {
|
||||
throw new NotFoundException();
|
||||
|
@ -277,7 +277,7 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
try {
|
||||
final Map.Entry<String, String> uriMap = Commons.parseEntityURI(link);
|
||||
final Map.Entry<String, InputStream> entity =
|
||||
readEntity(uriMap.getKey(), uriMap.getValue(), Accept.JSON_FULLMETA);
|
||||
readEntity(uriMap.getKey(), uriMap.getValue(), Accept.JSON_FULLMETA);
|
||||
|
||||
if (bos.size() > 1) {
|
||||
bos.write(",".getBytes());
|
||||
|
@ -295,7 +295,7 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
}
|
||||
|
||||
node.set(Constants.get(version, ConstantKey.JSON_VALUE_NAME),
|
||||
mapper.readTree(new ByteArrayInputStream(bos.toByteArray())));
|
||||
mapper.readTree(new ByteArrayInputStream(bos.toByteArray())));
|
||||
|
||||
if (StringUtils.isNotBlank(next)) {
|
||||
node.set(Constants.get(version, ConstantKey.JSON_NEXTLINK_NAME), new TextNode(next));
|
||||
|
@ -306,8 +306,8 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
protected InputStream replaceLink(
|
||||
final InputStream toBeChanged, final String linkName, final InputStream replacement)
|
||||
throws IOException {
|
||||
final InputStream toBeChanged, final String linkName, final InputStream replacement)
|
||||
throws IOException {
|
||||
|
||||
final ObjectNode toBeChangedNode = (ObjectNode) mapper.readTree(toBeChanged);
|
||||
final ObjectNode replacementNode = (ObjectNode) mapper.readTree(replacement);
|
||||
|
@ -343,7 +343,7 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public Map.Entry<String, List<String>> extractLinkURIs(
|
||||
final String entitySetName, final String entityId, final String linkName) throws Exception {
|
||||
final String entitySetName, final String entityId, final String linkName) throws Exception {
|
||||
final LinkInfo links = readLinks(entitySetName, entityId, linkName, Accept.JSON_FULLMETA);
|
||||
return extractLinkURIs(links.getLinks());
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public InputStream addEditLink(
|
||||
final InputStream content, final String title, final String href) throws IOException {
|
||||
final InputStream content, final String title, final String href) throws IOException {
|
||||
|
||||
final ObjectNode srcNode = (ObjectNode) mapper.readTree(content);
|
||||
IOUtils.closeQuietly(content);
|
||||
|
@ -387,7 +387,7 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public InputStream addOperation(final InputStream content, final String name, final String metaAnchor,
|
||||
final String href) throws IOException {
|
||||
final String href) throws IOException {
|
||||
|
||||
final ObjectNode srcNode = (ObjectNode) mapper.readTree(content);
|
||||
IOUtils.closeQuietly(content);
|
||||
|
@ -402,8 +402,8 @@ public class JSONUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public InputStream replaceProperty(
|
||||
final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
|
||||
throws IOException {
|
||||
final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
|
||||
throws IOException {
|
||||
|
||||
final ObjectNode srcNode = (ObjectNode) mapper.readTree(src);
|
||||
IOUtils.closeQuietly(src);
|
||||
|
|
|
@ -101,11 +101,11 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
}
|
||||
|
||||
private void skipElement(
|
||||
final StartElement start,
|
||||
final XMLEventReader reader,
|
||||
final XMLEventWriter writer,
|
||||
final boolean excludeStart)
|
||||
throws Exception {
|
||||
final StartElement start,
|
||||
final XMLEventReader reader,
|
||||
final XMLEventWriter writer,
|
||||
final boolean excludeStart)
|
||||
throws Exception {
|
||||
|
||||
if (!excludeStart) {
|
||||
writeEvent(start, writer);
|
||||
|
@ -133,8 +133,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
*/
|
||||
@Override
|
||||
protected InputStream addLinks(
|
||||
final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
|
||||
throws Exception {
|
||||
final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
|
||||
throws Exception {
|
||||
|
||||
// -----------------------------------------
|
||||
// 0. Build reader and writer
|
||||
|
@ -146,7 +146,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
final XMLEventWriter writer = getEventWriter(bos);
|
||||
// -----------------------------------------
|
||||
final Map.Entry<Integer, XMLElement> entry =
|
||||
extractElement(reader, writer, Collections.singletonList("entry"), 0, 1, 1);
|
||||
extractElement(reader, writer, Collections.singletonList("entry"), 0, 1, 1);
|
||||
|
||||
writer.add(entry.getValue().getStart());
|
||||
|
||||
|
@ -157,16 +157,16 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
final Set<Attribute> attributes = new HashSet<Attribute>();
|
||||
attributes.add(eventFactory.createAttribute(new QName("title"), link));
|
||||
attributes.add(eventFactory.createAttribute(new QName("href"),
|
||||
Commons.getLinksURI(entitySetName, entitykey, link)));
|
||||
Commons.getLinksURI(entitySetName, entitykey, link)));
|
||||
attributes.add(eventFactory.createAttribute(new QName("rel"),
|
||||
Constants.get(version, ConstantKey.ATOM_LINK_REL) + link));
|
||||
Constants.get(version, ConstantKey.ATOM_LINK_REL) + link));
|
||||
attributes.add(eventFactory.createAttribute(new QName("type"),
|
||||
navigationProperties.get(link).isEntitySet()
|
||||
navigationProperties.get(link).isEntitySet()
|
||||
? Constants.get(version, ConstantKey.ATOM_LINK_FEED)
|
||||
: Constants.get(version, ConstantKey.ATOM_LINK_ENTRY)));
|
||||
|
||||
writer.add(eventFactory.createStartElement(
|
||||
new QName(Constants.get(version, ConstantKey.LINK)), attributes.iterator(), null));
|
||||
new QName(Constants.get(version, ConstantKey.LINK)), attributes.iterator(), null));
|
||||
writer.add(eventFactory.createEndElement(new QName(Constants.get(version, ConstantKey.LINK)), null));
|
||||
}
|
||||
|
||||
|
@ -197,8 +197,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
while (true) {
|
||||
final Map.Entry<Integer, XMLElement> linkInfo =
|
||||
extractElement(reader, null,
|
||||
Collections.<String> singletonList(Constants.get(version, ConstantKey.LINK)), startDepth, 2, 2);
|
||||
extractElement(reader, null,
|
||||
Collections.<String>singletonList(Constants.get(version, ConstantKey.LINK)), startDepth, 2, 2);
|
||||
|
||||
startDepth = linkInfo.getKey();
|
||||
|
||||
|
@ -219,8 +219,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
*/
|
||||
@Override
|
||||
protected NavigationLinks retrieveNavigationInfo(
|
||||
final String entitySetName, final InputStream is)
|
||||
throws Exception {
|
||||
final String entitySetName, final InputStream is)
|
||||
throws Exception {
|
||||
|
||||
final NavigationLinks links = new NavigationLinks();
|
||||
|
||||
|
@ -236,8 +236,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
while (true) {
|
||||
// a. search for link with type attribute equals to "application/atom+xml;type=entry/feed"
|
||||
final Map.Entry<Integer, XMLElement> linkInfo = extractElement(
|
||||
reader, null, Collections.<String> singletonList(Constants.get(version, ConstantKey.LINK)),
|
||||
filter, true, startDepth, 2, 2);
|
||||
reader, null, Collections.<String>singletonList(Constants.get(version, ConstantKey.LINK)),
|
||||
filter, true, startDepth, 2, 2);
|
||||
final XMLElement link = linkInfo.getValue();
|
||||
startDepth = linkInfo.getKey();
|
||||
|
||||
|
@ -248,15 +248,15 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
try {
|
||||
final XMLElement inlineElement =
|
||||
extractElement(link.getContentReader(version), null,
|
||||
Collections.<String> singletonList(Constants.get(version, ConstantKey.INLINE)), 0, -1, -1).
|
||||
extractElement(link.getContentReader(version), null,
|
||||
Collections.<String>singletonList(Constants.get(version, ConstantKey.INLINE)), 0, -1, -1).
|
||||
getValue();
|
||||
final XMLEventReader inlineReader = inlineElement.getContentReader(version);
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
final XMLElement entry =
|
||||
extractElement(inlineReader, null, Collections.<String> singletonList("entry"), 0, -1, -1).
|
||||
extractElement(inlineReader, null, Collections.<String>singletonList("entry"), 0, -1, -1).
|
||||
getValue();
|
||||
links.addInlines(title, entry.toStream());
|
||||
}
|
||||
|
@ -286,8 +286,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
*/
|
||||
@Override
|
||||
protected InputStream normalizeLinks(
|
||||
final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
|
||||
throws Exception {
|
||||
final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
|
||||
throws Exception {
|
||||
|
||||
// -----------------------------------------
|
||||
// 0. Build reader and writer
|
||||
|
@ -317,9 +317,9 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
while (true) {
|
||||
// a. search for link with type attribute equals to "application/atom+xml;type=entry/feed"
|
||||
linkInfo = extractElement(
|
||||
reader, writer,
|
||||
Collections.<String> singletonList(Constants.get(version, ConstantKey.LINK)), filter, true,
|
||||
linkInfo == null ? 0 : linkInfo.getKey(), 2, 2);
|
||||
reader, writer,
|
||||
Collections.<String>singletonList(Constants.get(version, ConstantKey.LINK)), filter, true,
|
||||
linkInfo == null ? 0 : linkInfo.getKey(), 2, 2);
|
||||
final XMLElement link = linkInfo.getValue();
|
||||
|
||||
final String title = link.getStart().getAttributeByName(new QName("title")).getValue();
|
||||
|
@ -328,13 +328,13 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
added.add(title);
|
||||
|
||||
final String normalizedLink = String.format(
|
||||
"<link href=\"%s(%s)/%s\" rel=\"%s\" title=\"%s\" type=\"%s\"/>",
|
||||
entitySetName,
|
||||
entityKey,
|
||||
title,
|
||||
link.getStart().getAttributeByName(new QName("rel")).getValue(),
|
||||
title,
|
||||
link.getStart().getAttributeByName(new QName("type")).getValue());
|
||||
"<link href=\"%s(%s)/%s\" rel=\"%s\" title=\"%s\" type=\"%s\"/>",
|
||||
entitySetName,
|
||||
entityKey,
|
||||
title,
|
||||
link.getStart().getAttributeByName(new QName("rel")).getValue(),
|
||||
title,
|
||||
link.getStart().getAttributeByName(new QName("type")).getValue());
|
||||
|
||||
addAtomElement(IOUtils.toInputStream(normalizedLink, Constants.ENCODING), writer);
|
||||
}
|
||||
|
@ -348,29 +348,29 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
// -----------------------------------------
|
||||
|
||||
// -----------------------------------------
|
||||
// 2. Add edit link if missing
|
||||
// 2. Add/replace edit link
|
||||
// -----------------------------------------
|
||||
final InputStream content = addEditLink(
|
||||
new ByteArrayInputStream(tmpBos.toByteArray()),
|
||||
entitySetName,
|
||||
Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL) + entitySetName + "(" + entityKey + ")");
|
||||
new ByteArrayInputStream(tmpBos.toByteArray()),
|
||||
entitySetName,
|
||||
Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL) + entitySetName + "(" + entityKey + ")");
|
||||
// -----------------------------------------
|
||||
|
||||
// -----------------------------------------
|
||||
// 3. Add content element if missing
|
||||
// -----------------------------------------
|
||||
return addAtomContent(
|
||||
content,
|
||||
entitySetName,
|
||||
Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL) + entitySetName + "(" + entityKey + ")");
|
||||
content,
|
||||
entitySetName,
|
||||
Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL) + entitySetName + "(" + entityKey + ")");
|
||||
// -----------------------------------------
|
||||
|
||||
}
|
||||
|
||||
public XMLElement getXmlElement(
|
||||
final StartElement start,
|
||||
final XMLEventReader reader)
|
||||
throws Exception {
|
||||
final StartElement start,
|
||||
final XMLEventReader reader)
|
||||
throws Exception {
|
||||
|
||||
final XMLElement res = new XMLElement();
|
||||
res.setStart(start);
|
||||
|
@ -406,9 +406,9 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
}
|
||||
|
||||
private void addAtomElement(
|
||||
final InputStream content,
|
||||
final XMLEventWriter writer)
|
||||
throws Exception {
|
||||
final InputStream content,
|
||||
final XMLEventWriter writer)
|
||||
throws Exception {
|
||||
final XMLEventReader reader = getEventReader(content);
|
||||
|
||||
final XMLEventFactory eventFactory = XMLEventFactory.newInstance();
|
||||
|
@ -421,8 +421,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
final XMLEvent event = reader.nextEvent();
|
||||
|
||||
if (event.getEventType() != XMLStreamConstants.START_DOCUMENT
|
||||
&& event.getEventType() != XMLStreamConstants.END_DOCUMENT
|
||||
&& event.getEventType() != XMLStreamConstants.COMMENT) {
|
||||
&& event.getEventType() != XMLStreamConstants.END_DOCUMENT
|
||||
&& event.getEventType() != XMLStreamConstants.COMMENT) {
|
||||
writer.add(event);
|
||||
}
|
||||
}
|
||||
|
@ -435,8 +435,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public InputStream addEditLink(
|
||||
final InputStream content, final String title, final String href)
|
||||
throws Exception {
|
||||
final InputStream content, final String title, final String href)
|
||||
throws Exception {
|
||||
|
||||
final ByteArrayOutputStream copy = new ByteArrayOutputStream();
|
||||
IOUtils.copy(content, copy);
|
||||
|
@ -448,11 +448,11 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
XMLEventWriter writer = getEventWriter(bos);
|
||||
|
||||
final String editLinkElement = String.format("<link rel=\"edit\" title=\"%s\" href=\"%s\" />", title, href);
|
||||
|
||||
System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA replace with " + editLinkElement);
|
||||
try {
|
||||
// check edit link existence
|
||||
extractElement(reader, writer, Collections.<String> singletonList(Constants.get(version, ConstantKey.LINK)),
|
||||
Collections.<Map.Entry<String, String>> singletonList(
|
||||
extractElement(reader, writer, Collections.<String>singletonList(Constants.get(version, ConstantKey.LINK)),
|
||||
Collections.<Map.Entry<String, String>>singletonList(
|
||||
new AbstractMap.SimpleEntry<String, String>("rel", "edit")), false, 0, -1, -1);
|
||||
|
||||
addAtomElement(IOUtils.toInputStream(editLinkElement, Constants.ENCODING), writer);
|
||||
|
@ -466,7 +466,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
writer = getEventWriter(bos);
|
||||
|
||||
final XMLElement entryElement =
|
||||
extractElement(reader, writer, Collections.<String> singletonList("entry"), 0, 1, 1).getValue();
|
||||
extractElement(reader, writer, Collections.<String>singletonList("entry"), 0, 1, 1).getValue();
|
||||
|
||||
writer.add(entryElement.getStart());
|
||||
|
||||
|
@ -488,22 +488,22 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public InputStream addOperation(final InputStream content, final String name, final String metaAnchor,
|
||||
final String href) throws Exception {
|
||||
final String href) throws Exception {
|
||||
|
||||
final ByteArrayOutputStream copy = new ByteArrayOutputStream();
|
||||
IOUtils.copy(content, copy);
|
||||
IOUtils.closeQuietly(content);
|
||||
|
||||
final String action = String.format("<m:action metadata=\"%s%s\" title=\"%s\" target=\"%s\"/>",
|
||||
Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL), metaAnchor, name, href);
|
||||
Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL), metaAnchor, name, href);
|
||||
final String newContent = new String(copy.toByteArray(), "UTF-8").replaceAll("\\<content ", action + "\\<content ");
|
||||
|
||||
return IOUtils.toInputStream(newContent, "UTF-8");
|
||||
}
|
||||
|
||||
private InputStream addAtomContent(
|
||||
final InputStream content, final String title, final String href)
|
||||
throws Exception {
|
||||
final InputStream content, final String title, final String href)
|
||||
throws Exception {
|
||||
|
||||
final ByteArrayOutputStream copy = new ByteArrayOutputStream();
|
||||
IOUtils.copy(content, copy);
|
||||
|
@ -518,7 +518,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
try {
|
||||
// check edit link existence
|
||||
XMLElement contentElement =
|
||||
extractElement(reader, writer, Collections.<String> singletonList("content"), 0, 2, 2).getValue();
|
||||
extractElement(reader, writer, Collections.<String>singletonList("content"), 0, 2, 2).getValue();
|
||||
writer.add(contentElement.getStart());
|
||||
writer.add(contentElement.getContentReader(version));
|
||||
writer.add(contentElement.getEnd());
|
||||
|
@ -532,33 +532,33 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
if (isMediaContent(title)) {
|
||||
final XMLElement entryElement =
|
||||
extractElement(reader, writer, Collections.<String> singletonList("entry"), 0, 1, 1).getValue();
|
||||
extractElement(reader, writer, Collections.<String>singletonList("entry"), 0, 1, 1).getValue();
|
||||
|
||||
writer.add(entryElement.getStart());
|
||||
writer.add(entryElement.getContentReader(version));
|
||||
|
||||
addAtomElement(
|
||||
IOUtils.toInputStream(String.format("<content type=\"*/*\" src=\"%s/$value\" />", href)),
|
||||
writer);
|
||||
IOUtils.toInputStream(String.format("<content type=\"*/*\" src=\"%s/$value\" />", href)),
|
||||
writer);
|
||||
|
||||
writer.add(entryElement.getEnd());
|
||||
} else {
|
||||
try {
|
||||
final XMLElement entryElement =
|
||||
extractElement(reader, writer, Collections.<String> singletonList(
|
||||
extractElement(reader, writer, Collections.<String>singletonList(
|
||||
Constants.get(version, ConstantKey.PROPERTIES)), 0, 2, 3).getValue();
|
||||
|
||||
addAtomElement(
|
||||
IOUtils.toInputStream("<content type=\"application/xml\">"),
|
||||
writer);
|
||||
IOUtils.toInputStream("<content type=\"application/xml\">"),
|
||||
writer);
|
||||
|
||||
writer.add(entryElement.getStart());
|
||||
writer.add(entryElement.getContentReader(version));
|
||||
writer.add(entryElement.getEnd());
|
||||
|
||||
addAtomElement(
|
||||
IOUtils.toInputStream("</content>"),
|
||||
writer);
|
||||
IOUtils.toInputStream("</content>"),
|
||||
writer);
|
||||
} catch (Exception nf) {
|
||||
reader.close();
|
||||
reader = getEventReader(new ByteArrayInputStream(copy.toByteArray()));
|
||||
|
@ -567,13 +567,13 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
writer = getEventWriter(bos);
|
||||
|
||||
final XMLElement entryElement =
|
||||
extractElement(reader, writer, Collections.<String> singletonList("entry"), 0, 1, 1).getValue();
|
||||
extractElement(reader, writer, Collections.<String>singletonList("entry"), 0, 1, 1).getValue();
|
||||
writer.add(entryElement.getStart());
|
||||
writer.add(entryElement.getContentReader(version));
|
||||
|
||||
addAtomElement(
|
||||
IOUtils.toInputStream("<content type=\"application/xml\"/>"),
|
||||
writer);
|
||||
IOUtils.toInputStream("<content type=\"application/xml\"/>"),
|
||||
writer);
|
||||
|
||||
writer.add(entryElement.getEnd());
|
||||
}
|
||||
|
@ -593,10 +593,10 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
public int countAllElements(final String entitySetName) throws Exception {
|
||||
final String basePath = entitySetName + File.separatorChar;
|
||||
int count = countFeedElements(fsManager.readFile(basePath + Constants.get(version, ConstantKey.FEED), Accept.XML),
|
||||
"entry");
|
||||
"entry");
|
||||
|
||||
final String skipTokenDirPath =
|
||||
fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.SKIP_TOKEN),
|
||||
fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.SKIP_TOKEN),
|
||||
null);
|
||||
|
||||
try {
|
||||
|
@ -605,7 +605,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
for (FileObject file : files) {
|
||||
count += countFeedElements(fsManager.readFile(
|
||||
basePath + Constants.get(version, ConstantKey.SKIP_TOKEN) + File.separatorChar
|
||||
basePath + Constants.get(version, ConstantKey.SKIP_TOKEN) + File.separatorChar
|
||||
+ file.getName().getBaseName(), null), "entry");
|
||||
}
|
||||
} catch (FileSystemException fse) {
|
||||
|
@ -624,7 +624,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
final XMLEvent event = reader.nextEvent();
|
||||
|
||||
if (event.getEventType() == XMLStreamConstants.START_ELEMENT
|
||||
&& elementName.equals(event.asStartElement().getName().getLocalPart())) {
|
||||
&& elementName.equals(event.asStartElement().getName().getLocalPart())) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
@ -634,18 +634,18 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
}
|
||||
|
||||
public Map.Entry<Integer, XMLElement> extractElement(
|
||||
final XMLEventReader reader, final XMLEventWriter writer, final List<String> path,
|
||||
final int startPathPos, final int minPathPos, final int maxPathPos)
|
||||
throws Exception {
|
||||
final XMLEventReader reader, final XMLEventWriter writer, final List<String> path,
|
||||
final int startPathPos, final int minPathPos, final int maxPathPos)
|
||||
throws Exception {
|
||||
return extractElement(reader, writer, path, null, false, startPathPos, minPathPos, maxPathPos);
|
||||
}
|
||||
|
||||
public Map.Entry<Integer, XMLElement> extractElement(
|
||||
final XMLEventReader reader, final XMLEventWriter writer, final List<String> path,
|
||||
final Collection<Map.Entry<String, String>> filter,
|
||||
final boolean filterInOr,
|
||||
final int startPathPos, final int minPathPos, final int maxPathPos)
|
||||
throws Exception {
|
||||
final XMLEventReader reader, final XMLEventWriter writer, final List<String> path,
|
||||
final Collection<Map.Entry<String, String>> filter,
|
||||
final boolean filterInOr,
|
||||
final int startPathPos, final int minPathPos, final int maxPathPos)
|
||||
throws Exception {
|
||||
|
||||
StartElement start = null;
|
||||
int searchFor = 0;
|
||||
|
@ -655,9 +655,9 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
String current = null;
|
||||
|
||||
// set defaults
|
||||
final List<String> pathElementNames = path == null ? Collections.<String> emptyList() : path;
|
||||
final List<String> pathElementNames = path == null ? Collections.<String>emptyList() : path;
|
||||
final Collection<Map.Entry<String, String>> filterAttrs =
|
||||
filter == null ? Collections.<Map.Entry<String, String>> emptySet() : filter;
|
||||
filter == null ? Collections.<Map.Entry<String, String>>emptySet() : filter;
|
||||
|
||||
while (reader.hasNext() && start == null) {
|
||||
final XMLEvent event = reader.nextEvent();
|
||||
|
@ -667,7 +667,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
if (current != null || ((minPathPos < 0 || minPathPos <= depth) && (maxPathPos < 0 || depth <= maxPathPos))) {
|
||||
if (pathElementNames.isEmpty()
|
||||
|| pathElementNames.get(searchFor).trim().equals(event.asStartElement().getName().getLocalPart())) {
|
||||
|| pathElementNames.get(searchFor).trim().equals(event.asStartElement().getName().getLocalPart())) {
|
||||
|
||||
if (searchFor < pathElementNames.size() - 1) {
|
||||
// path exploring not completed
|
||||
|
@ -739,7 +739,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
try {
|
||||
|
||||
final XMLElement feedElement =
|
||||
extractElement(reader, writer, Collections.<String> singletonList("feed"), 0, 1, 1).getValue();
|
||||
extractElement(reader, writer, Collections.<String>singletonList("feed"), 0, 1, 1).getValue();
|
||||
|
||||
writer.add(feedElement.getStart());
|
||||
addAtomElement(IOUtils.toInputStream(String.format("<m:count>%d</m:count>", count), Constants.ENCODING), writer);
|
||||
|
@ -779,22 +779,22 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
while (reader.hasNext()) {
|
||||
final XMLEvent event = reader.nextEvent();
|
||||
if (event.getEventType() == XMLStreamConstants.START_ELEMENT
|
||||
&& Constants.get(version, ConstantKey.LINK).equals(event.asStartElement().getName().getLocalPart())
|
||||
&& !fieldToBeSaved.contains(
|
||||
&& Constants.get(version, ConstantKey.LINK).equals(event.asStartElement().getName().getLocalPart())
|
||||
&& !fieldToBeSaved.contains(
|
||||
event.asStartElement().getAttributeByName(new QName("title")).getValue())
|
||||
&& !"edit".equals(event.asStartElement().getAttributeByName(new QName("rel")).getValue())) {
|
||||
&& !"edit".equals(event.asStartElement().getAttributeByName(new QName("rel")).getValue())) {
|
||||
writeCurrent = false;
|
||||
} else if (event.getEventType() == XMLStreamConstants.END_ELEMENT
|
||||
&& Constants.get(version, ConstantKey.LINK).equals(event.asEndElement().getName().getLocalPart())) {
|
||||
&& Constants.get(version, ConstantKey.LINK).equals(event.asEndElement().getName().getLocalPart())) {
|
||||
writeNext = true;
|
||||
} else if (event.getEventType() == XMLStreamConstants.START_ELEMENT
|
||||
&& (Constants.get(version, ConstantKey.PROPERTIES)).equals(
|
||||
&& (Constants.get(version, ConstantKey.PROPERTIES)).equals(
|
||||
event.asStartElement().getName().getLocalPart())) {
|
||||
writeCurrent = true;
|
||||
writeNext = false;
|
||||
inProperties = true;
|
||||
} else if (event.getEventType() == XMLStreamConstants.END_ELEMENT
|
||||
&& (Constants.get(version, ConstantKey.PROPERTIES)).equals(
|
||||
&& (Constants.get(version, ConstantKey.PROPERTIES)).equals(
|
||||
event.asEndElement().getName().getLocalPart())) {
|
||||
writeCurrent = true;
|
||||
} else if (inProperties) {
|
||||
|
@ -810,8 +810,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
}
|
||||
|
||||
} else if (event.getEventType() == XMLStreamConstants.END_ELEMENT
|
||||
&& StringUtils.isNotBlank(currentName)
|
||||
&& (Constants.get(version, ConstantKey.ATOM_PROPERTY_PREFIX) + currentName.trim()).equals(
|
||||
&& StringUtils.isNotBlank(currentName)
|
||||
&& (Constants.get(version, ConstantKey.ATOM_PROPERTY_PREFIX) + currentName.trim()).equals(
|
||||
event.asEndElement().getName().getLocalPart())) {
|
||||
writeNext = false;
|
||||
currentName = null;
|
||||
|
@ -843,8 +843,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public InputStream readEntities(
|
||||
final List<String> links, final String linkName, final String next, final boolean forceFeed)
|
||||
throws Exception {
|
||||
final List<String> links, final String linkName, final String next, final boolean forceFeed)
|
||||
throws Exception {
|
||||
|
||||
if (links.isEmpty()) {
|
||||
throw new NotFoundException();
|
||||
|
@ -861,14 +861,14 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
// build a feed
|
||||
|
||||
writer.write(("<feed xml:base=\"" + Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL) + "\" "
|
||||
+ "xmlns=\"http://www.w3.org/2005/Atom\" "
|
||||
+ "xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" "
|
||||
+ "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">")
|
||||
.toCharArray());
|
||||
+ "xmlns=\"http://www.w3.org/2005/Atom\" "
|
||||
+ "xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" "
|
||||
+ "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">")
|
||||
.toCharArray());
|
||||
|
||||
writer.write(("<id>" + Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL) + "entityset(entityid)/"
|
||||
+ linkName
|
||||
+ "</id>").toCharArray());
|
||||
+ linkName
|
||||
+ "</id>").toCharArray());
|
||||
|
||||
writer.write(("<title type=\"text\">" + linkName + "</title>").toCharArray());
|
||||
writer.write("<updated>2014-03-03T13:40:49Z</updated>".toCharArray());
|
||||
|
@ -880,10 +880,10 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
final Map.Entry<String, String> uri = Commons.parseEntityURI(link);
|
||||
|
||||
final XMLElement entry =
|
||||
extractElement(
|
||||
extractElement(
|
||||
getEventReader(readEntity(uri.getKey(), uri.getValue(), Accept.ATOM).getValue()),
|
||||
null,
|
||||
Collections.<String> singletonList("entry"),
|
||||
Collections.<String>singletonList("entry"),
|
||||
0, 1, 1).getValue();
|
||||
|
||||
IOUtils.copy(entry.toStream(), writer, encoding);
|
||||
|
@ -920,8 +920,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
XMLEventReader reader = getEventReader(new ByteArrayInputStream(bos.toByteArray()));
|
||||
|
||||
final Map.Entry<Integer, XMLElement> propertyElement =
|
||||
extractElement(reader, null,
|
||||
Collections.<String> singletonList(Constants.get(version, ConstantKey.PROPERTIES)), 0, 2, 3);
|
||||
extractElement(reader, null,
|
||||
Collections.<String>singletonList(Constants.get(version, ConstantKey.PROPERTIES)), 0, 2, 3);
|
||||
reader.close();
|
||||
|
||||
reader = propertyElement.getValue().getContentReader(version);
|
||||
|
@ -944,12 +944,12 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
int pos = 0;
|
||||
while (true) {
|
||||
final Map.Entry<Integer, XMLElement> linkElement =
|
||||
extractElement(reader, null,
|
||||
Collections.<String> singletonList(Constants.get(version, ConstantKey.LINK)), pos, 2, 2);
|
||||
extractElement(reader, null,
|
||||
Collections.<String>singletonList(Constants.get(version, ConstantKey.LINK)), pos, 2, 2);
|
||||
|
||||
res.put("[Constants.get(version, ConstantKey.LINK)]"
|
||||
+ linkElement.getValue().getStart().getAttributeByName(new QName("title")).getValue(),
|
||||
linkElement.getValue().toStream());
|
||||
+ linkElement.getValue().getStart().getAttributeByName(new QName("title")).getValue(),
|
||||
linkElement.getValue().toStream());
|
||||
|
||||
pos = linkElement.getKey();
|
||||
}
|
||||
|
@ -962,8 +962,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
protected InputStream replaceLink(
|
||||
final InputStream toBeChanged, final String linkName, final InputStream replacement)
|
||||
throws Exception {
|
||||
final InputStream toBeChanged, final String linkName, final InputStream replacement)
|
||||
throws Exception {
|
||||
final XMLEventReader reader = getEventReader(toBeChanged);
|
||||
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
@ -974,10 +974,10 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
try {
|
||||
final XMLElement linkElement =
|
||||
extractElement(reader, writer,
|
||||
Collections.<String> singletonList(Constants.get(version, ConstantKey.LINK)),
|
||||
Collections.<Map.Entry<String, String>> singletonList(
|
||||
new SimpleEntry<String, String>("title", linkName)), false, 0, -1, -1).getValue();
|
||||
extractElement(reader, writer,
|
||||
Collections.<String>singletonList(Constants.get(version, ConstantKey.LINK)),
|
||||
Collections.<Map.Entry<String, String>>singletonList(
|
||||
new SimpleEntry<String, String>("title", linkName)), false, 0, -1, -1).getValue();
|
||||
writer.add(linkElement.getStart());
|
||||
|
||||
// ------------------------------------------
|
||||
|
@ -1007,8 +1007,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public Map.Entry<String, List<String>> extractLinkURIs(
|
||||
final String entitySetName, final String entityId, final String linkName)
|
||||
throws Exception {
|
||||
final String entitySetName, final String entityId, final String linkName)
|
||||
throws Exception {
|
||||
|
||||
final LinkInfo links = readLinks(entitySetName, entityId, linkName, Accept.XML);
|
||||
return extractLinkURIs(links.getLinks());
|
||||
|
@ -1016,7 +1016,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public Map.Entry<String, List<String>> extractLinkURIs(final InputStream is)
|
||||
throws Exception {
|
||||
throws Exception {
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
IOUtils.copy(is, bos);
|
||||
IOUtils.closeQuietly(is);
|
||||
|
@ -1025,8 +1025,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
final List<String> links = new ArrayList<String>();
|
||||
try {
|
||||
while (true) {
|
||||
links.add(IOUtils.toString(extractElement(reader, null, Collections.<String> singletonList("uri"), 0, -1, -1).
|
||||
getValue().getContent()));
|
||||
links.add(IOUtils.toString(extractElement(reader, null, Collections.<String>singletonList("uri"), 0, -1, -1).
|
||||
getValue().getContent()));
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
// End document reached ...
|
||||
|
@ -1037,8 +1037,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
reader = getEventReader(new ByteArrayInputStream(bos.toByteArray()));
|
||||
try {
|
||||
next = IOUtils.toString(extractElement(reader, null, Collections.<String> singletonList("next"), 0, -1, -1).
|
||||
getValue().getContent());
|
||||
next = IOUtils.toString(extractElement(reader, null, Collections.<String>singletonList("next"), 0, -1, -1).
|
||||
getValue().getContent());
|
||||
} catch (Exception ignore) {
|
||||
// next link is not mandatory
|
||||
next = null;
|
||||
|
@ -1050,8 +1050,8 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
|
||||
@Override
|
||||
public InputStream replaceProperty(
|
||||
final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
|
||||
throws Exception {
|
||||
final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
|
||||
throws Exception {
|
||||
|
||||
final List<String> pathElements = new ArrayList<String>();
|
||||
|
||||
|
@ -1108,7 +1108,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
final XMLEventWriter writer = getEventWriter(bos);
|
||||
|
||||
final XMLEventReader changesReader = new XMLEventReaderWrapper(IOUtils.toInputStream(
|
||||
String.format("<%s m:null=\"true\" />", path.get(path.size() - 1)), Constants.ENCODING), version);
|
||||
String.format("<%s m:null=\"true\" />", path.get(path.size() - 1)), Constants.ENCODING), version);
|
||||
|
||||
writer.add(changesReader);
|
||||
changesReader.close();
|
||||
|
|
|
@ -90,9 +90,10 @@ public abstract class AbstractTestITCase {
|
|||
return customer;
|
||||
}
|
||||
|
||||
protected void createAndDeleteOrder(
|
||||
final InMemoryEntities container, final EntityContainerFactory<EdmEnabledODataClient> containerFactory) {
|
||||
protected void createPatchAndDeleteOrder(
|
||||
final InMemoryEntities container, final EntityContainerFactory<EdmEnabledODataClient> containerFactory) {
|
||||
|
||||
// Create order ....
|
||||
final Order order = container.getOrders().newOrder();
|
||||
order.setOrderID(105);
|
||||
|
||||
|
@ -101,17 +102,22 @@ public abstract class AbstractTestITCase {
|
|||
orderDate.set(2011, 3, 4, 16, 3, 57);
|
||||
order.setOrderDate(orderDate);
|
||||
|
||||
order.setShelfLife(BigDecimal.TEN);
|
||||
order.setOrderShelfLifes(Arrays.asList(new BigDecimal[] { BigDecimal.TEN.negate(), BigDecimal.TEN }));
|
||||
order.setShelfLife(BigDecimal.ZERO);
|
||||
order.setOrderShelfLifes(Arrays.asList(new BigDecimal[] {BigDecimal.TEN.negate(), BigDecimal.TEN}));
|
||||
|
||||
container.flush();
|
||||
|
||||
// Patch order ... (test for OLINGO-353)
|
||||
order.setShelfLife(BigDecimal.TEN);
|
||||
container.flush();
|
||||
|
||||
Order actual = container.getOrders().get(105);
|
||||
assertEquals(105, actual.getOrderID(), 0);
|
||||
assertEquals(orderDate.getTimeInMillis(), actual.getOrderDate().getTimeInMillis());
|
||||
assertEquals(BigDecimal.TEN, actual.getShelfLife());
|
||||
assertEquals(2, actual.getOrderShelfLifes().size());
|
||||
|
||||
// Delete order ...
|
||||
container.getOrders().delete(105);
|
||||
actual = container.getOrders().get(105);
|
||||
assertNull(actual);
|
||||
|
|
|
@ -66,7 +66,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
|||
|
||||
@Test
|
||||
public void createAndDelete() {
|
||||
createAndDeleteOrder(getContainer(), getContainerFactory());
|
||||
createPatchAndDeleteOrder(getContainer(), getContainerFactory());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -57,7 +57,7 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
|
|||
|
||||
@Test
|
||||
public void createAndDelete() {
|
||||
createAndDeleteOrder(getContainer(), getContainerFactory());
|
||||
createPatchAndDeleteOrder(getContainer(), getContainerFactory());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -44,7 +44,7 @@ public class UnauthorizedEntityCreateTestITCase extends AbstractTestITCase {
|
|||
|
||||
@Test(expected = HttpClientException.class)
|
||||
public void unauthorizedCreate() {
|
||||
createAndDeleteOrder(getContainer(), getContainerFactory());
|
||||
createPatchAndDeleteOrder(getContainer(), getContainerFactory());
|
||||
}
|
||||
|
||||
protected InMemoryEntities getContainer() {
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse
|
|||
import org.apache.olingo.client.api.uri.v3.URIBuilder;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import static org.apache.olingo.fit.v3.AbstractTestITCase.client;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -38,9 +39,14 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
|
|||
client.getConfiguration().setKeyAsSegment(true);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void disableKeyAsSegment() {
|
||||
client.getConfiguration().setKeyAsSegment(false);
|
||||
}
|
||||
|
||||
private void read(final ODataFormat format) {
|
||||
final URIBuilder uriBuilder = client.newURIBuilder(testKeyAsSegmentServiceRootURL).
|
||||
appendEntitySetSegment("Customer").appendKeySegment(-10);
|
||||
appendEntitySetSegment("Customer").appendKeySegment(-10);
|
||||
|
||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||
req.setFormat(format);
|
||||
|
@ -91,7 +97,7 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
|
|||
public void replaceODataEntityAsAtom() {
|
||||
final ODataFormat format = ODataFormat.ATOM;
|
||||
final ODataEntity changes = read(format, client.newURIBuilder(testKeyAsSegmentServiceRootURL).
|
||||
appendEntitySetSegment("Car").appendKeySegment(14).build());
|
||||
appendEntitySetSegment("Car").appendKeySegment(14).build());
|
||||
updateEntityDescription(format, changes, UpdateType.REPLACE);
|
||||
}
|
||||
|
||||
|
@ -99,12 +105,7 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
|
|||
public void replaceODataEntityAsJSON() {
|
||||
final ODataFormat format = ODataFormat.JSON_FULL_METADATA;
|
||||
final ODataEntity changes = read(format, client.newURIBuilder(testKeyAsSegmentServiceRootURL).
|
||||
appendEntitySetSegment("Car").appendKeySegment(14).build());
|
||||
appendEntitySetSegment("Car").appendKeySegment(14).build());
|
||||
updateEntityDescription(format, changes, UpdateType.REPLACE);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void disableKeyAsSegment() {
|
||||
client.getConfiguration().setKeyAsSegment(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.olingo.client.core.uri;
|
|||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
|
|
Loading…
Reference in New Issue