[OLINGO-603] Delete core dependecies in Tec Scenario
This commit is contained in:
parent
d4c2b89e46
commit
05935a0c3d
|
@ -81,10 +81,6 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
|||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.serialization.ODataDeserializer;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializer;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.commons.core.serialization.AtomSerializer;
|
||||
import org.apache.olingo.commons.core.serialization.JsonDeserializer;
|
||||
|
@ -231,14 +227,14 @@ public abstract class AbstractServices {
|
|||
@GET
|
||||
@Path("/StoredPIs(1000)")
|
||||
public Response getStoredPI(@Context final UriInfo uriInfo) {
|
||||
final Entity entity = new EntityImpl();
|
||||
final Entity entity = new Entity();
|
||||
entity.setType("Microsoft.Test.OData.Services.ODataWCFService.StoredPI");
|
||||
final Property id = new PropertyImpl();
|
||||
final Property id = new Property();
|
||||
id.setType("Edm.Int32");
|
||||
id.setName("StoredPIID");
|
||||
id.setValue(ValueType.PRIMITIVE, 1000);
|
||||
entity.getProperties().add(id);
|
||||
final Link edit = new LinkImpl();
|
||||
final Link edit = new Link();
|
||||
edit.setHref(uriInfo.getRequestUri().toASCIIString());
|
||||
edit.setRel("edit");
|
||||
edit.setTitle("StoredPI");
|
||||
|
@ -622,7 +618,7 @@ public abstract class AbstractServices {
|
|||
final Entity entry;
|
||||
final String entityKey;
|
||||
if (xml.isMediaContent(entitySetName)) {
|
||||
entry = new EntityImpl();
|
||||
entry = new Entity();
|
||||
entry.setMediaContentType(ContentType.APPLICATION_OCTET_STREAM.toContentTypeString());
|
||||
entry.setType(entitySet.getType());
|
||||
|
||||
|
@ -632,7 +628,7 @@ public abstract class AbstractServices {
|
|||
|
||||
final Pair<String, EdmPrimitiveTypeKind> id = Commons.getMediaContent().get(entitySetName);
|
||||
if (id != null) {
|
||||
final Property prop = new PropertyImpl();
|
||||
final Property prop = new Property();
|
||||
prop.setName(id.getKey());
|
||||
prop.setType(id.getValue().toString());
|
||||
prop.setValue(ValueType.PRIMITIVE,
|
||||
|
@ -644,7 +640,7 @@ public abstract class AbstractServices {
|
|||
entry.getProperties().add(prop);
|
||||
}
|
||||
|
||||
final Link editLink = new LinkImpl();
|
||||
final Link editLink = new Link();
|
||||
editLink.setHref(Commons.getEntityURI(entitySetName, entityKey));
|
||||
editLink.setRel("edit");
|
||||
editLink.setTitle(entitySetName);
|
||||
|
@ -691,7 +687,7 @@ public abstract class AbstractServices {
|
|||
if ((this instanceof V4KeyAsSegment)) {
|
||||
location = uriInfo.getRequestUri().toASCIIString() + "/" + entityKey;
|
||||
|
||||
final Link editLink = new LinkImpl();
|
||||
final Link editLink = new Link();
|
||||
editLink.setRel("edit");
|
||||
editLink.setTitle(entitySetName);
|
||||
editLink.setHref(location);
|
||||
|
@ -1207,7 +1203,7 @@ public abstract class AbstractServices {
|
|||
final Entity entry = container.getPayload();
|
||||
|
||||
if ((this instanceof V4KeyAsSegment)) {
|
||||
final Link editLink = new LinkImpl();
|
||||
final Link editLink = new Link();
|
||||
editLink.setRel("edit");
|
||||
editLink.setTitle(entitySetName);
|
||||
editLink.setHref(Constants.get(ConstantKey.DEFAULT_SERVICE_URL) + entitySetName + "/" + entityId);
|
||||
|
@ -1248,7 +1244,7 @@ public abstract class AbstractServices {
|
|||
for (Link link : entry.getNavigationLinks()) {
|
||||
if (links.contains(link.getTitle())) {
|
||||
// expand link
|
||||
final Link rep = new LinkImpl();
|
||||
final Link rep = new Link();
|
||||
rep.setHref(link.getHref());
|
||||
rep.setRel(link.getRel());
|
||||
rep.setTitle(link.getTitle());
|
||||
|
@ -1904,7 +1900,7 @@ public abstract class AbstractServices {
|
|||
|
||||
for (Property property : entity.getProperties()) {
|
||||
if (navProperties.containsKey(property.getName())) {
|
||||
Link alink = new LinkImpl();
|
||||
Link alink = new Link();
|
||||
alink.setTitle(property.getName());
|
||||
alink.getAnnotations().addAll(property.getAnnotations());
|
||||
|
||||
|
@ -1915,9 +1911,9 @@ public abstract class AbstractServices {
|
|||
alink.setRel(Constants.get(ConstantKey.ATOM_LINK_REL) + property.getName());
|
||||
|
||||
if (property.isCollection()) {
|
||||
EntitySet inline = new EntitySetImpl();
|
||||
EntitySet inline = new EntitySet();
|
||||
for (Object value : property.asCollection()) {
|
||||
Entity inlineEntity = new EntityImpl();
|
||||
Entity inlineEntity = new Entity();
|
||||
inlineEntity.setType(navProperties.get(property.getName()).getType());
|
||||
for (Property prop : ((ComplexValue) value).getValue()) {
|
||||
inlineEntity.getProperties().add(prop);
|
||||
|
@ -1926,7 +1922,7 @@ public abstract class AbstractServices {
|
|||
}
|
||||
alink.setInlineEntitySet(inline);
|
||||
} else if (property.isComplex()) {
|
||||
Entity inline = new EntityImpl();
|
||||
Entity inline = new Entity();
|
||||
inline.setType(navProperties.get(property.getName()).getType());
|
||||
for (Property prop : property.asComplex().getValue()) {
|
||||
inline.getProperties().add(prop);
|
||||
|
@ -1946,7 +1942,7 @@ public abstract class AbstractServices {
|
|||
final EntityType entityType = metadata.getEntityOrComplexType(entitySet.getType());
|
||||
for (Map.Entry<String, org.apache.olingo.fit.metadata.Property> property : entityType.getPropertyMap().entrySet()) {
|
||||
if (entry.getProperty(property.getKey()) == null && property.getValue().isNullable()) {
|
||||
final PropertyImpl prop = new PropertyImpl();
|
||||
final Property prop = new Property();
|
||||
prop.setName(property.getKey());
|
||||
prop.setValue(ValueType.PRIMITIVE, null);
|
||||
entry.getProperties().add(prop);
|
||||
|
@ -1962,7 +1958,7 @@ public abstract class AbstractServices {
|
|||
}
|
||||
|
||||
if (!found) {
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
link.setTitle(property.getKey());
|
||||
link.setType(property.getValue().isEntitySet()
|
||||
? Constants.get(ConstantKey.ATOM_LINK_FEED)
|
||||
|
|
|
@ -18,42 +18,25 @@
|
|||
*/
|
||||
package org.apache.olingo.fit;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.cxf.interceptor.InInterceptors;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
|
||||
import org.apache.olingo.fit.metadata.Metadata;
|
||||
import org.apache.olingo.fit.methods.PATCH;
|
||||
import org.apache.olingo.fit.rest.ResolvingReferencesInterceptor;
|
||||
import org.apache.olingo.fit.rest.XHTTPMethodInterceptor;
|
||||
import org.apache.olingo.fit.utils.AbstractUtilities;
|
||||
import org.apache.olingo.fit.utils.Accept;
|
||||
import org.apache.olingo.fit.utils.Commons;
|
||||
import org.apache.olingo.fit.utils.ConstantKey;
|
||||
import org.apache.olingo.fit.utils.Constants;
|
||||
import org.apache.olingo.fit.utils.FSManager;
|
||||
import org.apache.olingo.fit.utils.LinkInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import javax.ws.rs.BadRequestException;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
|
@ -72,23 +55,35 @@ import javax.ws.rs.core.Response;
|
|||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.ws.rs.BadRequestException;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.cxf.interceptor.InInterceptors;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
|
||||
import org.apache.olingo.fit.metadata.Metadata;
|
||||
import org.apache.olingo.fit.methods.PATCH;
|
||||
import org.apache.olingo.fit.rest.ResolvingReferencesInterceptor;
|
||||
import org.apache.olingo.fit.rest.XHTTPMethodInterceptor;
|
||||
import org.apache.olingo.fit.utils.AbstractUtilities;
|
||||
import org.apache.olingo.fit.utils.Accept;
|
||||
import org.apache.olingo.fit.utils.Commons;
|
||||
import org.apache.olingo.fit.utils.ConstantKey;
|
||||
import org.apache.olingo.fit.utils.Constants;
|
||||
import org.apache.olingo.fit.utils.FSManager;
|
||||
import org.apache.olingo.fit.utils.LinkInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Path("/V40/Static.svc")
|
||||
|
@ -504,7 +499,7 @@ public class V4Services extends AbstractServices {
|
|||
acceptType = Accept.parse(accept);
|
||||
}
|
||||
|
||||
final Property property = new PropertyImpl();
|
||||
final Property property = new Property();
|
||||
property.setType("Edm.Int32");
|
||||
property.setValue(ValueType.PRIMITIVE, 2);
|
||||
final ResWrap<Property> container = new ResWrap<Property>(
|
||||
|
@ -565,27 +560,27 @@ public class V4Services extends AbstractServices {
|
|||
acceptType = Accept.parse(accept);
|
||||
}
|
||||
|
||||
final EntityImpl entry = new EntityImpl();
|
||||
final Entity entry = new Entity();
|
||||
entry.setType("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail");
|
||||
final Property productId = new PropertyImpl();
|
||||
final Property productId = new Property();
|
||||
productId.setName("ProductID");
|
||||
productId.setType("Edm.Int32");
|
||||
productId.setValue(ValueType.PRIMITIVE, Integer.valueOf(entityId));
|
||||
entry.getProperties().add(productId);
|
||||
final Property productDetailId = new PropertyImpl();
|
||||
final Property productDetailId = new Property();
|
||||
productDetailId.setName("ProductDetailID");
|
||||
productDetailId.setType("Edm.Int32");
|
||||
productDetailId.setValue(ValueType.PRIMITIVE, 2);
|
||||
entry.getProperties().add(productDetailId);
|
||||
|
||||
final Link link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
link.setRel("edit");
|
||||
link.setHref(URI.create(
|
||||
Constants.get(ConstantKey.DEFAULT_SERVICE_URL)
|
||||
+ "ProductDetails(ProductID=6,ProductDetailID=1)").toASCIIString());
|
||||
entry.setEditLink(link);
|
||||
|
||||
final EntitySetImpl feed = new EntitySetImpl();
|
||||
final EntitySet feed = new EntitySet();
|
||||
feed.getEntities().add(entry);
|
||||
|
||||
final ResWrap<EntitySet> container = new ResWrap<EntitySet>(
|
||||
|
@ -736,7 +731,7 @@ public class V4Services extends AbstractServices {
|
|||
acceptType = Accept.parse(accept);
|
||||
}
|
||||
|
||||
final Property property = new PropertyImpl();
|
||||
final Property property = new Property();
|
||||
property.setType("Edm.Double");
|
||||
property.setValue(ValueType.PRIMITIVE, 41.79);
|
||||
|
||||
|
@ -1144,7 +1139,7 @@ public class V4Services extends AbstractServices {
|
|||
acceptType = Accept.parse(accept);
|
||||
}
|
||||
|
||||
final PropertyImpl property = new PropertyImpl();
|
||||
final Property property = new Property();
|
||||
property.setType("Microsoft.Test.OData.Services.ODataWCFService.Color");
|
||||
property.setValue(ValueType.ENUM, "Red");
|
||||
final ResWrap<Property> container = new ResWrap<Property>(
|
||||
|
@ -1236,7 +1231,7 @@ public class V4Services extends AbstractServices {
|
|||
acceptType = Accept.parse(accept);
|
||||
}
|
||||
|
||||
final PropertyImpl property = new PropertyImpl();
|
||||
final Property property = new Property();
|
||||
property.setType("Collection(String)");
|
||||
final List<String> value = Arrays.asList("Cheetos", "Mushrooms", "Apple", "Car", "Computer");
|
||||
property.setValue(ValueType.COLLECTION_PRIMITIVE, value);
|
||||
|
@ -1268,7 +1263,7 @@ public class V4Services extends AbstractServices {
|
|||
acceptType = Accept.parse(accept);
|
||||
}
|
||||
|
||||
final PropertyImpl property = new PropertyImpl();
|
||||
final Property property = new Property();
|
||||
property.setType("Collection(Edm.String)");
|
||||
property.setValue(ValueType.COLLECTION_PRIMITIVE,
|
||||
Arrays.asList("first@olingo.apache.org", "second@olingo.apache.org"));
|
||||
|
|
|
@ -87,12 +87,6 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
|||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
import org.apache.olingo.commons.core.data.AnnotationImpl;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.domain.ODataAnnotationImpl;
|
||||
import org.apache.olingo.commons.core.domain.ODataDeletedEntityImpl;
|
||||
import org.apache.olingo.commons.core.domain.ODataDeltaLinkImpl;
|
||||
|
@ -187,7 +181,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
|
||||
private void annotations(final ODataAnnotatable odataAnnotatable, final Annotatable annotatable) {
|
||||
for (ODataAnnotation odataAnnotation : odataAnnotatable.getAnnotations()) {
|
||||
final Annotation annotation = new AnnotationImpl();
|
||||
final Annotation annotation = new Annotation();
|
||||
|
||||
annotation.setTerm(odataAnnotation.getTerm());
|
||||
annotation.setType(odataAnnotation.getValue().getTypeName());
|
||||
|
@ -199,7 +193,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
|
||||
@Override
|
||||
public EntitySet getEntitySet(final ODataEntitySet odataEntitySet) {
|
||||
final EntitySet entitySet = new EntitySetImpl();
|
||||
final EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.setCount(odataEntitySet.getCount());
|
||||
|
||||
|
@ -248,7 +242,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
|
||||
@Override
|
||||
public Entity getEntity(final ODataEntity odataEntity) {
|
||||
final Entity entity = new EntityImpl();
|
||||
final Entity entity = new Entity();
|
||||
|
||||
entity.setType(odataEntity.getTypeName() == null ? null : odataEntity.getTypeName().toString());
|
||||
|
||||
|
@ -257,7 +251,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
// -------------------------------------------------------------
|
||||
final URI odataEditLink = odataEntity.getEditLink();
|
||||
if (odataEditLink != null) {
|
||||
final LinkImpl editLink = new LinkImpl();
|
||||
final Link editLink = new Link();
|
||||
editLink.setTitle(entity.getType());
|
||||
editLink.setHref(odataEditLink.toASCIIString());
|
||||
editLink.setRel(Constants.EDIT_LINK_REL);
|
||||
|
@ -265,7 +259,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
}
|
||||
|
||||
if (odataEntity.isReadOnly()) {
|
||||
final LinkImpl selfLink = new LinkImpl();
|
||||
final Link selfLink = new Link();
|
||||
selfLink.setTitle(entity.getType());
|
||||
selfLink.setHref(odataEntity.getLink().toASCIIString());
|
||||
selfLink.setRel(Constants.SELF_LINK_REL);
|
||||
|
@ -301,7 +295,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
|
||||
@Override
|
||||
public Link getLink(final ODataLink link) {
|
||||
final Link linkResource = new LinkImpl();
|
||||
final Link linkResource = new Link();
|
||||
linkResource.setRel(link.getRel());
|
||||
linkResource.setTitle(link.getName());
|
||||
linkResource.setHref(link.getLink() == null ? null : link.getLink().toASCIIString());
|
||||
|
@ -328,7 +322,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
@Override
|
||||
public Property getProperty(final ODataProperty property) {
|
||||
|
||||
final Property propertyResource = new PropertyImpl();
|
||||
final Property propertyResource = new Property();
|
||||
propertyResource.setName(property.getName());
|
||||
updateValuable(propertyResource, property);
|
||||
annotations(property, propertyResource);
|
||||
|
@ -350,7 +344,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
for (final ODataProperty propertyValue : value.asComplex()) {
|
||||
complexProperties.add(getProperty(propertyValue));
|
||||
}
|
||||
final ComplexValue lcValueResource = new ComplexValueImpl();
|
||||
final ComplexValue lcValueResource = new ComplexValue();
|
||||
lcValueResource.getValue().addAll(complexProperties);
|
||||
annotations(value.asComplex(), lcValueResource);
|
||||
links(value.asComplex(), lcValueResource);
|
||||
|
@ -573,16 +567,16 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
|
||||
private ODataLink createLinkFromNavigationProperty(final Property property, final String propertyTypeName) {
|
||||
if (property.isCollection()) {
|
||||
EntitySet inlineEntitySet = new EntitySetImpl();
|
||||
EntitySet inlineEntitySet = new EntitySet();
|
||||
for (final Object inlined : property.asCollection()) {
|
||||
Entity inlineEntity = new EntityImpl();
|
||||
Entity inlineEntity = new Entity();
|
||||
inlineEntity.setType(propertyTypeName);
|
||||
inlineEntity.getProperties().addAll(((ComplexValue) inlined).getValue());
|
||||
inlineEntitySet.getEntities().add(inlineEntity);
|
||||
}
|
||||
return createODataInlineEntitySet(inlineEntitySet, null, property.getName(), null);
|
||||
} else {
|
||||
Entity inlineEntity = new EntityImpl();
|
||||
Entity inlineEntity = new Entity();
|
||||
inlineEntity.setType(propertyTypeName);
|
||||
inlineEntity.getProperties().addAll(property.asComplex().getValue());
|
||||
return createODataInlineEntity(inlineEntity, null, property.getName(), null);
|
||||
|
@ -751,7 +745,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
value = client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
|
||||
|
||||
for (Object _value : valuable.asCollection()) {
|
||||
final Property fake = new PropertyImpl();
|
||||
final Property fake = new Property();
|
||||
fake.setValue(valuable.getValueType().getBaseType(), _value);
|
||||
value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ public class JSONTest extends AbstractTest {
|
|||
final StringWriter writer = new StringWriter();
|
||||
getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toEntity(
|
||||
getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload());
|
||||
|
||||
|
||||
assertSimilar(filename + "." + getSuffix(format), writer.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -16,17 +16,22 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
import java.net.URI;
|
||||
import java.text.ParseException;
|
||||
|
||||
public abstract class AbstractODataObject extends AbstractAnnotatedObject {
|
||||
public abstract class AbstractODataObject extends Annotatable {
|
||||
|
||||
private URI baseURI;
|
||||
private URI id;
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* Gets base URI.
|
||||
*
|
||||
* @return base URI.
|
||||
*/
|
||||
public URI getBaseURI() {
|
||||
return baseURI;
|
||||
}
|
||||
|
@ -35,6 +40,12 @@ public abstract class AbstractODataObject extends AbstractAnnotatedObject {
|
|||
this.baseURI = baseURI == null ? null : URI.create(baseURI);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gest ID.
|
||||
*
|
||||
* @return ID.
|
||||
*/
|
||||
public URI getId() {
|
||||
return id;
|
||||
}
|
|
@ -18,12 +18,37 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* An element with instance annotations.
|
||||
*/
|
||||
public interface Annotatable {
|
||||
public abstract class Annotatable {
|
||||
|
||||
List<Annotation> getAnnotations();
|
||||
private final List<Annotation> annotations = new ArrayList<Annotation>();
|
||||
|
||||
public List<Annotation> getAnnotations() {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,15 @@ package org.apache.olingo.commons.api.data;
|
|||
/**
|
||||
* Represents an instance annotation.
|
||||
*/
|
||||
public interface Annotation extends Valuable {
|
||||
public class Annotation extends Valuable {
|
||||
|
||||
String getTerm();
|
||||
private String term;
|
||||
|
||||
void setTerm(String term);
|
||||
public String getTerm() {
|
||||
return term;
|
||||
}
|
||||
|
||||
public void setTerm(final String term) {
|
||||
this.term = term;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,14 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface ComplexValue extends Linked, Annotatable {
|
||||
public class ComplexValue extends Linked {
|
||||
|
||||
List<Property> getValue();
|
||||
private final List<Property> value = new ArrayList<Property>();
|
||||
|
||||
public List<Property> getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,17 +20,31 @@ package org.apache.olingo.commons.api.data;
|
|||
|
||||
import java.net.URI;
|
||||
|
||||
public interface DeletedEntity {
|
||||
public class DeletedEntity {
|
||||
|
||||
enum Reason {
|
||||
public enum Reason {
|
||||
|
||||
deleted,
|
||||
changed
|
||||
|
||||
}
|
||||
|
||||
URI getId();
|
||||
private URI id;
|
||||
private Reason reason;
|
||||
|
||||
Reason getReason();
|
||||
public URI getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final URI id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Reason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public void setReason(final Reason reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,25 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface Delta extends EntitySet {
|
||||
public class Delta extends EntitySet {
|
||||
|
||||
List<DeletedEntity> getDeletedEntities();
|
||||
private final List<DeletedEntity> deletedEntities = new ArrayList<DeletedEntity>();
|
||||
private final List<DeltaLink> addedLinks = new ArrayList<DeltaLink>();
|
||||
private final List<DeltaLink> deletedLinks = new ArrayList<DeltaLink>();
|
||||
|
||||
List<DeltaLink> getAddedLinks();
|
||||
public List<DeletedEntity> getDeletedEntities() {
|
||||
return deletedEntities;
|
||||
}
|
||||
|
||||
List<DeltaLink> getDeletedLinks();
|
||||
public List<DeltaLink> getAddedLinks() {
|
||||
return addedLinks;
|
||||
}
|
||||
|
||||
public List<DeltaLink> getDeletedLinks() {
|
||||
return deletedLinks;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,17 +20,33 @@ package org.apache.olingo.commons.api.data;
|
|||
|
||||
import java.net.URI;
|
||||
|
||||
public interface DeltaLink extends Annotatable {
|
||||
public class DeltaLink extends Annotatable {
|
||||
|
||||
URI getSource();
|
||||
private URI source;
|
||||
private String relationship;
|
||||
private URI target;
|
||||
|
||||
void setSource(URI source);
|
||||
public URI getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
String getRelationship();
|
||||
public void setSource(final URI source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
void setRelationship(String relationship);
|
||||
public String getRelationship() {
|
||||
return relationship;
|
||||
}
|
||||
|
||||
URI getTarget();
|
||||
public void setRelationship(final String relationship) {
|
||||
this.relationship = relationship;
|
||||
}
|
||||
|
||||
void setTarget(URI target);
|
||||
public URI getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(final URI target) {
|
||||
this.target = target;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,93 +21,110 @@ package org.apache.olingo.commons.api.data;
|
|||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface Entity extends Linked, Annotatable {
|
||||
public class Entity extends Linked {
|
||||
|
||||
private String eTag;
|
||||
private String type;
|
||||
|
||||
private Link readLink;
|
||||
private Link editLink;
|
||||
|
||||
private final List<Link> mediaEditLinks = new ArrayList<Link>();
|
||||
private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
|
||||
|
||||
private final List<Property> properties = new ArrayList<Property>();
|
||||
|
||||
private URI mediaContentSource;
|
||||
private String mediaContentType;
|
||||
private String mediaETag;
|
||||
|
||||
/**
|
||||
* Gets ETag.
|
||||
*
|
||||
* @return ETag.
|
||||
*/
|
||||
String getETag();
|
||||
public String getETag() {
|
||||
return eTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets base URI.
|
||||
*
|
||||
* @return base URI.
|
||||
*/
|
||||
URI getBaseURI();
|
||||
public void setETag(final String eTag) {
|
||||
this.eTag = eTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets entity type.
|
||||
*
|
||||
* @return entity type.
|
||||
*/
|
||||
String getType();
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets entity type.
|
||||
*
|
||||
* @param type entity type.
|
||||
*/
|
||||
void setType(String type);
|
||||
|
||||
/**
|
||||
* Gets entity ID.
|
||||
*
|
||||
* @return entity ID.
|
||||
*/
|
||||
URI getId();
|
||||
|
||||
/**
|
||||
* Sets entity ID.
|
||||
*
|
||||
* @param id entity ID.
|
||||
*/
|
||||
void setId(URI id);
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets entity self link.
|
||||
*
|
||||
* @return self link.
|
||||
*/
|
||||
Link getSelfLink();
|
||||
public Link getSelfLink() {
|
||||
return readLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets entity self link.
|
||||
*
|
||||
* @param selfLink self link.
|
||||
*/
|
||||
void setSelfLink(Link selfLink);
|
||||
public void setSelfLink(final Link selfLink) {
|
||||
this.readLink = selfLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets entity edit link.
|
||||
*
|
||||
* @return edit link.
|
||||
*/
|
||||
Link getEditLink();
|
||||
public Link getEditLink() {
|
||||
return editLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets entity edit link.
|
||||
*
|
||||
* @param editLink edit link.
|
||||
*/
|
||||
void setEditLink(Link editLink);
|
||||
public void setEditLink(final Link editLink) {
|
||||
this.editLink = editLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets media entity links.
|
||||
*
|
||||
* @return links.
|
||||
*/
|
||||
List<Link> getMediaEditLinks();
|
||||
public List<Link> getMediaEditLinks() {
|
||||
return mediaEditLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets operations.
|
||||
*
|
||||
* @return operations.
|
||||
*/
|
||||
List<ODataOperation> getOperations();
|
||||
public List<ODataOperation> getOperations() {
|
||||
return operations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add property to this Entity.
|
||||
|
@ -115,14 +132,19 @@ public interface Entity extends Linked, Annotatable {
|
|||
* @param property property which is added
|
||||
* @return this Entity for fluid/flow adding
|
||||
*/
|
||||
Entity addProperty(Property property);
|
||||
public Entity addProperty(final Property property) {
|
||||
properties.add(property);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets properties.
|
||||
*
|
||||
* @return properties.
|
||||
*/
|
||||
List<Property> getProperties();
|
||||
public List<Property> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets property with given name.
|
||||
|
@ -130,54 +152,78 @@ public interface Entity extends Linked, Annotatable {
|
|||
* @param name property name
|
||||
* @return property with given name if found, null otherwise
|
||||
*/
|
||||
Property getProperty(String name);
|
||||
public Property getProperty(final String name) {
|
||||
Property result = null;
|
||||
|
||||
for (Property property : properties) {
|
||||
if (name.equals(property.getName())) {
|
||||
result = property;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets media content type.
|
||||
*
|
||||
* @return media content type.
|
||||
*/
|
||||
String getMediaContentType();
|
||||
|
||||
/**
|
||||
* Gets media content resource.
|
||||
*
|
||||
* @return media content resource.
|
||||
*/
|
||||
URI getMediaContentSource();
|
||||
|
||||
/**
|
||||
* Set media content source.
|
||||
*
|
||||
* @param mediaContentSource media content source.
|
||||
*/
|
||||
void setMediaContentSource(URI mediaContentSource);
|
||||
public String getMediaContentType() {
|
||||
return mediaContentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set media content type.
|
||||
*
|
||||
* @param mediaContentType media content type.
|
||||
*/
|
||||
void setMediaContentType(String mediaContentType);
|
||||
public void setMediaContentType(final String mediaContentType) {
|
||||
this.mediaContentType = mediaContentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets media content resource.
|
||||
*
|
||||
* @return media content resource.
|
||||
*/
|
||||
public URI getMediaContentSource() {
|
||||
return mediaContentSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set media content source.
|
||||
*
|
||||
* @param mediaContentSource media content source.
|
||||
*/
|
||||
public void setMediaContentSource(final URI mediaContentSource) {
|
||||
this.mediaContentSource = mediaContentSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* ETag of the binary stream represented by this media entity or named stream property.
|
||||
*
|
||||
* @return media ETag value
|
||||
*/
|
||||
String getMediaETag();
|
||||
public String getMediaETag() {
|
||||
return mediaETag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set media ETag.
|
||||
*
|
||||
* @param eTag media ETag value
|
||||
*/
|
||||
void setMediaETag(String eTag);
|
||||
public void setMediaETag(final String eTag) {
|
||||
mediaETag = eTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current entity is a media entity.
|
||||
*
|
||||
* @return 'TRUE' if is a media entity; 'FALSE' otherwise.
|
||||
*/
|
||||
boolean isMediaEntity();
|
||||
public boolean isMediaEntity() {
|
||||
return mediaContentSource != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,70 +19,79 @@
|
|||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface EntitySet extends Annotatable {
|
||||
public class EntitySet extends AbstractODataObject {
|
||||
|
||||
/**
|
||||
* Gets base URI.
|
||||
*
|
||||
* @return base URI.
|
||||
*/
|
||||
URI getBaseURI();
|
||||
private Integer count;
|
||||
|
||||
private final List<Entity> entities = new ArrayList<Entity>();
|
||||
|
||||
private URI next;
|
||||
|
||||
private URI deltaLink;
|
||||
|
||||
/**
|
||||
* Sets number of entries.
|
||||
*
|
||||
* @param count number of entries
|
||||
*/
|
||||
void setCount(Integer count);
|
||||
public void setCount(final Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number of entries - if it was required.
|
||||
*
|
||||
* @return number of entries into the entity set.
|
||||
*/
|
||||
Integer getCount();
|
||||
|
||||
/**
|
||||
* Gest ID.
|
||||
*
|
||||
* @return ID.
|
||||
*/
|
||||
URI getId();
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets entities.
|
||||
*
|
||||
* @return entries.
|
||||
*/
|
||||
List<Entity> getEntities();
|
||||
|
||||
/**
|
||||
* Gets next link if exists.
|
||||
*
|
||||
* @return next link if exists; null otherwise.
|
||||
*/
|
||||
URI getNext();
|
||||
public List<Entity> getEntities() {
|
||||
return entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets next link.
|
||||
*
|
||||
* @param next next link.
|
||||
*/
|
||||
void setNext(URI next);
|
||||
public void setNext(final URI next) {
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets next link if exists.
|
||||
*
|
||||
* @return next link if exists; null otherwise.
|
||||
*/
|
||||
public URI getNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets delta link if exists.
|
||||
*
|
||||
* @return delta link if exists; null otherwise.
|
||||
*/
|
||||
URI getDeltaLink();
|
||||
public URI getDeltaLink() {
|
||||
return deltaLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets delta link.
|
||||
*
|
||||
* @param deltaLink delta link.
|
||||
*/
|
||||
void setDeltaLink(URI deltaLink);
|
||||
public void setDeltaLink(final URI deltaLink) {
|
||||
this.deltaLink = deltaLink;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,130 +18,177 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface Link extends Annotatable {
|
||||
public class Link extends Annotatable {
|
||||
|
||||
/**
|
||||
* Gets rel info.
|
||||
*
|
||||
* @return rel info.
|
||||
*/
|
||||
String getRel();
|
||||
|
||||
/**
|
||||
* Sets rel info.
|
||||
*
|
||||
* @param rel rel info.
|
||||
*/
|
||||
void setRel(String rel);
|
||||
|
||||
/**
|
||||
* Gets type.
|
||||
*
|
||||
* @return type.
|
||||
*/
|
||||
String getType();
|
||||
|
||||
/**
|
||||
* Sets type.
|
||||
*
|
||||
* @param type type.
|
||||
*/
|
||||
void setType(String type);
|
||||
private String title;
|
||||
private String rel;
|
||||
private String href;
|
||||
private String type;
|
||||
private String mediaETag;
|
||||
private Entity entity;
|
||||
private EntitySet entitySet;
|
||||
private String bindingLink;
|
||||
private List<String> bindingLinks = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* Gets title.
|
||||
*
|
||||
* @return title.
|
||||
*/
|
||||
String getTitle();
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets title.
|
||||
*
|
||||
* @param title title.
|
||||
*/
|
||||
void setTitle(String title);
|
||||
public void setTitle(final String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets rel info.
|
||||
*
|
||||
* @return rel info.
|
||||
*/
|
||||
public String getRel() {
|
||||
return rel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets rel info.
|
||||
*
|
||||
* @param rel rel info.
|
||||
*/
|
||||
public void setRel(final String rel) {
|
||||
this.rel = rel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets href.
|
||||
*
|
||||
* @return href.
|
||||
*/
|
||||
String getHref();
|
||||
public String getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets href.
|
||||
*
|
||||
* @param href href.
|
||||
*/
|
||||
void setHref(String href);
|
||||
public void setHref(final String href) {
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets type.
|
||||
*
|
||||
* @return type.
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets type.
|
||||
*
|
||||
* @param type type.
|
||||
*/
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Media ETag.
|
||||
*
|
||||
* @return media ETag
|
||||
*/
|
||||
String getMediaETag();
|
||||
public String getMediaETag() {
|
||||
return mediaETag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Media ETag.
|
||||
*
|
||||
* @param etag media ETag
|
||||
* @param mediaETag media ETag
|
||||
*/
|
||||
void setMediaETag(String etag);
|
||||
public void setMediaETag(final String mediaETag) {
|
||||
this.mediaETag = mediaETag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets in-line entity.
|
||||
*
|
||||
* @return in-line entity.
|
||||
*/
|
||||
Entity getInlineEntity();
|
||||
public Entity getInlineEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets in-line entity.
|
||||
*
|
||||
* @param entity entity.
|
||||
*/
|
||||
void setInlineEntity(Entity entity);
|
||||
public void setInlineEntity(final Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets in-line entity set.
|
||||
*
|
||||
* @return in-line entity set.
|
||||
*/
|
||||
EntitySet getInlineEntitySet();
|
||||
public EntitySet getInlineEntitySet() {
|
||||
return entitySet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets in-line entity set.
|
||||
*
|
||||
* @param entitySet entity set.
|
||||
*/
|
||||
void setInlineEntitySet(EntitySet entitySet);
|
||||
public void setInlineEntitySet(final EntitySet entitySet) {
|
||||
this.entitySet = entitySet;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this is a "toOne" relationship this method delivers the binding link or <tt>null</tt> if not set.
|
||||
* @return String the binding link.
|
||||
*/
|
||||
String getBindingLink();
|
||||
|
||||
/**
|
||||
* Sets the binding link.
|
||||
* @param bindingLink
|
||||
*/
|
||||
void setBindingLink(String bindingLink);
|
||||
public String getBindingLink() {
|
||||
return bindingLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this is a "toMany" relationship this method delivers the binding links or <tt>emptyList</tt> if not set.
|
||||
* @return a list of binding links.
|
||||
*/
|
||||
List<String> getBindingLinks();
|
||||
public List<String> getBindingLinks() {
|
||||
return bindingLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the binding link.
|
||||
* @param bindingLink
|
||||
*/
|
||||
public void setBindingLink(String bindingLink) {
|
||||
this.bindingLink = bindingLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the binding links. List MUST NOT be <tt>null</tt>.
|
||||
* @param bindingLinks
|
||||
*/
|
||||
void setBindingLinks(List<String> bindingLinks);
|
||||
|
||||
public void setBindingLinks(List<String> bindingLinks) {
|
||||
this.bindingLinks = bindingLinks;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,26 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface Linked {
|
||||
public abstract class Linked extends AbstractODataObject {
|
||||
|
||||
private final List<Link> associationLinks = new ArrayList<Link>();
|
||||
private final List<Link> navigationLinks = new ArrayList<Link>();
|
||||
private final List<Link> bindingLinks = new ArrayList<Link>();
|
||||
|
||||
protected Link getOneByTitle(final String name, final List<Link> links) {
|
||||
Link result = null;
|
||||
|
||||
for (Link link : links) {
|
||||
if (name.equals(link.getTitle())) {
|
||||
result = link;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets association link with given name, if available, otherwise <tt>null</tt>.
|
||||
|
@ -28,14 +45,18 @@ public interface Linked {
|
|||
* @param name candidate link name
|
||||
* @return association link with given name, if available, otherwise <tt>null</tt>
|
||||
*/
|
||||
Link getAssociationLink(String name);
|
||||
public Link getAssociationLink(final String name) {
|
||||
return getOneByTitle(name, associationLinks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets association links.
|
||||
*
|
||||
* @return association links.
|
||||
*/
|
||||
List<Link> getAssociationLinks();
|
||||
public List<Link> getAssociationLinks() {
|
||||
return associationLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets navigation link with given name, if available, otherwise <tt>null</tt>.
|
||||
|
@ -43,26 +64,34 @@ public interface Linked {
|
|||
* @param name candidate link name
|
||||
* @return navigation link with given name, if available, otherwise <tt>null</tt>
|
||||
*/
|
||||
Link getNavigationLink(String name);
|
||||
public Link getNavigationLink(final String name) {
|
||||
return getOneByTitle(name, navigationLinks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets navigation links.
|
||||
*
|
||||
* @return links.
|
||||
*/
|
||||
List<Link> getNavigationLinks();
|
||||
public List<Link> getNavigationLinks() {
|
||||
return navigationLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets binding link with given name, if available, otherwise <tt>null</tt>.
|
||||
* @param name candidate link name
|
||||
* @return binding link with given name, if available, otherwise <tt>null</tt>
|
||||
*/
|
||||
Link getNavigationBinding(String name);
|
||||
public Link getNavigationBinding(String name) {
|
||||
return getOneByTitle(name, bindingLinks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets binding links.
|
||||
*
|
||||
* @return links.
|
||||
*/
|
||||
List<Link> getNavigationBindings();
|
||||
public List<Link> getNavigationBindings() {
|
||||
return bindingLinks;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,15 +18,46 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
public interface Parameter extends Valuable {
|
||||
public class Parameter extends Valuable {
|
||||
|
||||
String name;
|
||||
|
||||
/**
|
||||
* @return name of the parameter
|
||||
*/
|
||||
String getName();
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
boolean isEntity();
|
||||
|
||||
Entity asEntity();
|
||||
/**
|
||||
* @param name of the parameter
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a ENTITY or COLLECTION_ENTITY ValueType
|
||||
*
|
||||
* @return true if ValueType is a ENTITY or COLLECTION_ENTITY, otherwise false
|
||||
*/
|
||||
public boolean isEntity() {
|
||||
if (isCollection()) {
|
||||
return getValueType().getBaseType() == ValueType.ENTITY;
|
||||
}
|
||||
return getValueType() == ValueType.ENTITY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value in its entity representation or null if it is not based on an entity ValueType
|
||||
*
|
||||
* @return entity representation or null if it is not based on an entity ValueType
|
||||
*/
|
||||
public Entity asEntity() {
|
||||
if (isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isEntity() ? (Entity) getValue() : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,9 +18,32 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
public interface Property extends Valuable, Annotatable {
|
||||
public class Property extends Valuable {
|
||||
|
||||
String getName();
|
||||
private String name;
|
||||
|
||||
void setName(String name);
|
||||
public Property() {}
|
||||
|
||||
public Property(final String type, final String name) {
|
||||
this.name = name;
|
||||
super.setType(type);
|
||||
}
|
||||
|
||||
public Property(String type, String name, ValueType valueType, Object value) {
|
||||
this(type, name);
|
||||
setValue(valueType, value);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return getValue() == null || "Edm.Null".equals(getType());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,96 +18,178 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Valuable {
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
|
||||
String getType();
|
||||
public abstract class Valuable extends Annotatable {
|
||||
|
||||
void setType(String type);
|
||||
private ValueType valueType = null;
|
||||
private Object value = null;
|
||||
private String type;
|
||||
|
||||
boolean isNull();
|
||||
public boolean isNull() {
|
||||
return value == null;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a PRIMITIVE or COLLECTION_PRIMITIVE ValueType
|
||||
*
|
||||
* @return true if ValueType is a PRIMITIVE or COLLECTION_PRIMITIVE, otherwise false
|
||||
*/
|
||||
boolean isPrimitive();
|
||||
public boolean isPrimitive() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.PRIMITIVE;
|
||||
}
|
||||
return valueType == ValueType.PRIMITIVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a GEOSPATIAL or COLLECTION_GEOSPATIAL ValueType
|
||||
*
|
||||
* @return true if ValueType is a GEOSPATIAL or COLLECTION_GEOSPATIAL, otherwise false
|
||||
*/
|
||||
boolean isGeospatial();
|
||||
public boolean isGeospatial() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.GEOSPATIAL;
|
||||
}
|
||||
return valueType == ValueType.GEOSPATIAL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a ENUM or COLLECTION_ENUM ValueType
|
||||
*
|
||||
* @return true if ValueType is a ENUM or COLLECTION_ENUM, otherwise false
|
||||
*/
|
||||
boolean isEnum();
|
||||
public boolean isEnum() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.ENUM;
|
||||
}
|
||||
return valueType == ValueType.ENUM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a COMPLEX or COLLECTION_COMPLEX ValueType
|
||||
*
|
||||
* @return true if ValueType is a COMPLEX or COLLECTION_COMPLEX, otherwise false
|
||||
*/
|
||||
boolean isComplex();
|
||||
public boolean isComplex() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.COMPLEX;
|
||||
}
|
||||
return valueType == ValueType.COMPLEX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Valuable contains a COLLECTION_* ValueType
|
||||
*
|
||||
* @return true if ValueType is a COLLECTION_*, otherwise false
|
||||
*/
|
||||
boolean isCollection();
|
||||
|
||||
/**
|
||||
* Get the value
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
Object getValue();
|
||||
public boolean isCollection() {
|
||||
return valueType != null && valueType != valueType.getBaseType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value in its primitive representation or null if it is not based on a primitive ValueType
|
||||
*
|
||||
* @return primitive representation or null if it is not based on a primitive ValueType
|
||||
*/
|
||||
Object asPrimitive();
|
||||
|
||||
/**
|
||||
* Get the value in its enum representation or null if it is not based on a enum ValueType
|
||||
*
|
||||
* @return enum representation or null if it is not based on a enum ValueType
|
||||
*/
|
||||
Object asEnum();
|
||||
public Object asPrimitive() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isPrimitive() ? value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value in its geospatial representation or null if it is not based on a geospatial ValueType
|
||||
*
|
||||
* @return geospatial representation or null if it is not based on a geospatial ValueType
|
||||
*/
|
||||
Geospatial asGeospatial();
|
||||
public Geospatial asGeospatial() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isGeospatial() ? (Geospatial) value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value in its enum representation or null if it is not based on a enum ValueType
|
||||
*
|
||||
* @return enum representation or null if it is not based on a enum ValueType
|
||||
*/
|
||||
public Object asEnum() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isEnum() ? value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value in its complex representation or null if it is not based on a complex ValueType
|
||||
*
|
||||
* @return primitive complex or null if it is not based on a complex ValueType
|
||||
*/
|
||||
ComplexValue asComplex();
|
||||
public ComplexValue asComplex() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isComplex() ? (ComplexValue) value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value as collection or null if it is not a collection ValueType
|
||||
*
|
||||
* @return collection or null if it is not a collection ValueType
|
||||
*/
|
||||
List<?> asCollection();
|
||||
public List<?> asCollection() {
|
||||
return isCollection() ? (List<?>) value : null;
|
||||
}
|
||||
|
||||
void setValue(ValueType valuetype, Object value);
|
||||
/**
|
||||
* Get the value
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
ValueType getValueType();
|
||||
public void setValue(final ValueType valueType, final Object value) {
|
||||
this.valueType = valueType;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public ValueType getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.apache.olingo.commons.api.data.Annotatable;
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractAnnotatedObject implements Annotatable {
|
||||
|
||||
private final List<Annotation> annotations = new ArrayList<Annotation>();
|
||||
|
||||
@Override
|
||||
public List<Annotation> getAnnotations() {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.apache.olingo.commons.api.data.Annotatable;
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Valuable;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
|
||||
public abstract class AbstractValuable implements Valuable, Annotatable {
|
||||
|
||||
private ValueType valueType = null;
|
||||
private Object value = null;
|
||||
private final List<Annotation> annotations = new ArrayList<Annotation>();
|
||||
private String type;
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return value == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrimitive() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.PRIMITIVE;
|
||||
}
|
||||
return valueType == ValueType.PRIMITIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeospatial() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.GEOSPATIAL;
|
||||
}
|
||||
return valueType == ValueType.GEOSPATIAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnum() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.ENUM;
|
||||
}
|
||||
return valueType == ValueType.ENUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplex() {
|
||||
if(isCollection()) {
|
||||
return valueType.getBaseType() == ValueType.COMPLEX;
|
||||
}
|
||||
return valueType == ValueType.COMPLEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCollection() {
|
||||
return valueType != null && valueType != valueType.getBaseType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asPrimitive() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isPrimitive() ? value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Geospatial asGeospatial() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isGeospatial() ? (Geospatial) value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object asEnum() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isEnum() ? value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComplexValue asComplex() {
|
||||
if(isCollection()) {
|
||||
return null;
|
||||
}
|
||||
return isComplex() ? (ComplexValue) value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> asCollection() {
|
||||
return isCollection() ? (List<?>) value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final ValueType valueType, final Object value) {
|
||||
this.valueType = valueType;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueType getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Annotation> getAnnotations() {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
|
||||
public class AnnotationImpl extends AbstractValuable implements Annotation {
|
||||
|
||||
private String term;
|
||||
|
||||
@Override
|
||||
public String getTerm() {
|
||||
return term;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerm(final String term) {
|
||||
this.term = term;
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ComplexValueImpl implements ComplexValue {
|
||||
|
||||
private final List<Property> value = new ArrayList<Property>();
|
||||
private final List<Link> associationLinks = new ArrayList<Link>();
|
||||
private final List<Link> navigationLinks = new ArrayList<Link>();
|
||||
private final List<Link> bindingLinks = new ArrayList<Link>();
|
||||
private final List<Annotation> annotations = new ArrayList<Annotation>();
|
||||
|
||||
@Override
|
||||
public List<Property> getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private Link getOneByTitle(final String name, final List<Link> links) {
|
||||
Link result = null;
|
||||
|
||||
for (Link link : links) {
|
||||
if (name.equals(link.getTitle())) {
|
||||
result = link;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Link getAssociationLink(final String name) {
|
||||
return getOneByTitle(name, associationLinks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Link> getAssociationLinks() {
|
||||
return associationLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Link getNavigationLink(final String name) {
|
||||
return getOneByTitle(name, navigationLinks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Link> getNavigationLinks() {
|
||||
return navigationLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Annotation> getAnnotations() {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Link getNavigationBinding(String name) {
|
||||
return getOneByTitle(name, bindingLinks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Link> getNavigationBindings() {
|
||||
return bindingLinks;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.olingo.commons.api.data.DeletedEntity;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class DeletedEntityImpl extends AbstractAnnotatedObject implements DeletedEntity {
|
||||
|
||||
private URI id;
|
||||
private Reason reason;
|
||||
|
||||
@Override
|
||||
public URI getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final URI id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public void setReason(final Reason reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.olingo.commons.api.data.DeletedEntity;
|
||||
import org.apache.olingo.commons.api.data.Delta;
|
||||
import org.apache.olingo.commons.api.data.DeltaLink;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeltaImpl extends EntitySetImpl implements Delta {
|
||||
|
||||
private final List<DeletedEntity> deletedEntities = new ArrayList<DeletedEntity>();
|
||||
private final List<DeltaLink> addedLinks = new ArrayList<DeltaLink>();
|
||||
private final List<DeltaLink> deletedLinks = new ArrayList<DeltaLink>();
|
||||
|
||||
@Override
|
||||
public List<DeletedEntity> getDeletedEntities() {
|
||||
return deletedEntities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeltaLink> getAddedLinks() {
|
||||
return addedLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeltaLink> getDeletedLinks() {
|
||||
return deletedLinks;
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.olingo.commons.api.data.DeltaLink;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class DeltaLinkImpl extends AbstractAnnotatedObject implements DeltaLink {
|
||||
|
||||
private URI source;
|
||||
private String relationship;
|
||||
private URI target;
|
||||
|
||||
@Override
|
||||
public URI getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSource(final URI source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRelationship() {
|
||||
return relationship;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRelationship(final String relationship) {
|
||||
this.relationship = relationship;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTarget(final URI target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,204 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class implementing an OData entity.
|
||||
*/
|
||||
public class EntityImpl extends AbstractODataObject implements Entity {
|
||||
|
||||
private String eTag;
|
||||
|
||||
private String type;
|
||||
|
||||
private Link readLink;
|
||||
private Link editLink;
|
||||
|
||||
private final List<Link> associationLinks = new ArrayList<Link>();
|
||||
private final List<Link> navigationLinks = new ArrayList<Link>();
|
||||
private final List<Link> mediaEditLinks = new ArrayList<Link>();
|
||||
private final List<Link> bindingLinks = new ArrayList<Link>();
|
||||
|
||||
private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
|
||||
|
||||
private final List<Property> properties = new ArrayList<Property>();
|
||||
|
||||
private URI mediaContentSource;
|
||||
private String mediaContentType;
|
||||
private String mediaETag;
|
||||
|
||||
@Override
|
||||
public String getETag() {
|
||||
return eTag;
|
||||
}
|
||||
|
||||
public void setETag(final String eTag) {
|
||||
this.eTag = eTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Link getSelfLink() {
|
||||
return readLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelfLink(final Link readLink) {
|
||||
this.readLink = readLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Link getEditLink() {
|
||||
return editLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEditLink(final Link editLink) {
|
||||
this.editLink = editLink;
|
||||
}
|
||||
|
||||
private Link getOneByTitle(final String name, final List<Link> links) {
|
||||
Link result = null;
|
||||
|
||||
for (Link link : links) {
|
||||
if (name.equals(link.getTitle())) {
|
||||
result = link;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Link getAssociationLink(final String name) {
|
||||
return getOneByTitle(name, associationLinks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Link> getAssociationLinks() {
|
||||
return associationLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Link getNavigationLink(final String name) {
|
||||
return getOneByTitle(name, navigationLinks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Link> getNavigationLinks() {
|
||||
return navigationLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Link> getMediaEditLinks() {
|
||||
return mediaEditLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Link getNavigationBinding(String name) {
|
||||
return getOneByTitle(name, bindingLinks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Link> getNavigationBindings() {
|
||||
return bindingLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ODataOperation> getOperations() {
|
||||
return operations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity addProperty(final Property property) {
|
||||
properties.add(property);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Property> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getProperty(final String name) {
|
||||
Property result = null;
|
||||
|
||||
for (Property property : properties) {
|
||||
if (name.equals(property.getName())) {
|
||||
result = property;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMediaContentType() {
|
||||
return mediaContentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaContentType(final String mediaContentType) {
|
||||
this.mediaContentType = mediaContentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getMediaContentSource() {
|
||||
return mediaContentSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaContentSource(final URI mediaContentSource) {
|
||||
this.mediaContentSource = mediaContentSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMediaETag() {
|
||||
return mediaETag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaETag(final String eTag) {
|
||||
mediaETag = eTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMediaEntity() {
|
||||
return mediaContentSource != null;
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EntitySetImpl extends AbstractODataObject implements EntitySet {
|
||||
|
||||
private Integer count;
|
||||
|
||||
private final List<Entity> entities = new ArrayList<Entity>();
|
||||
|
||||
private URI next;
|
||||
|
||||
private URI deltaLink;
|
||||
|
||||
@Override
|
||||
public void setCount(final Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getEntities() {
|
||||
return entities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNext(final URI next) {
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getDeltaLink() {
|
||||
return deltaLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeltaLink(final URI deltaLink) {
|
||||
this.deltaLink = deltaLink;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
|
||||
public class LinkImpl extends AbstractAnnotatedObject implements Link {
|
||||
|
||||
private String title;
|
||||
private String rel;
|
||||
private String href;
|
||||
private String type;
|
||||
private String mediaETag;
|
||||
private Entity entity;
|
||||
private EntitySet entitySet;
|
||||
private String bindingLink;
|
||||
private List<String> bindingLinks = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(final String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRel() {
|
||||
return rel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRel(final String rel) {
|
||||
this.rel = rel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHref(final String href) {
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMediaETag() {
|
||||
return mediaETag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaETag(final String mediaETag) {
|
||||
this.mediaETag = mediaETag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getInlineEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInlineEntity(final Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntitySet getInlineEntitySet() {
|
||||
return entitySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInlineEntitySet(final EntitySet entitySet) {
|
||||
this.entitySet = entitySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBindingLink() {
|
||||
return bindingLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getBindingLinks() {
|
||||
return bindingLinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBindingLink(String bindingLink) {
|
||||
this.bindingLink = bindingLink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBindingLinks(List<String> bindingLinks) {
|
||||
this.bindingLinks = bindingLinks;
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.Parameter;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
|
||||
public class ParameterImpl extends AbstractValuable implements Parameter {
|
||||
|
||||
String name;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntity() {
|
||||
return getValueType() == ValueType.ENTITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity asEntity() {
|
||||
return isEntity() ? (Entity) getValue() : null;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
|
||||
public class PropertyImpl extends AbstractValuable implements Property {
|
||||
|
||||
private String name;
|
||||
|
||||
public PropertyImpl() {}
|
||||
|
||||
public PropertyImpl(final String type, final String name) {
|
||||
this.name = name;
|
||||
super.setType(type);
|
||||
}
|
||||
|
||||
public PropertyImpl(String type, String name, ValueType valueType, Object value) {
|
||||
this(type, name);
|
||||
setValue(valueType, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return getValue() == null || "Edm.Null".equals(getType());
|
||||
}
|
||||
}
|
|
@ -36,12 +36,16 @@ import javax.xml.stream.events.XMLEvent;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.data.AbstractODataObject;
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.DeletedEntity;
|
||||
import org.apache.olingo.commons.api.data.DeletedEntity.Reason;
|
||||
import org.apache.olingo.commons.api.data.Delta;
|
||||
import org.apache.olingo.commons.api.data.DeltaLink;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.data.Valuable;
|
||||
|
@ -56,16 +60,6 @@ import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
|||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.serialization.ODataDeserializer;
|
||||
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
|
||||
import org.apache.olingo.commons.core.data.AbstractODataObject;
|
||||
import org.apache.olingo.commons.core.data.AnnotationImpl;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.DeletedEntityImpl;
|
||||
import org.apache.olingo.commons.core.data.DeltaImpl;
|
||||
import org.apache.olingo.commons.core.data.DeltaLinkImpl;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
|
||||
|
||||
import com.fasterxml.aalto.stax.InputFactoryImpl;
|
||||
|
@ -128,11 +122,11 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
|
||||
if (event.isStartElement()) {
|
||||
if (value == null) {
|
||||
value = new ComplexValueImpl();
|
||||
value = new ComplexValue();
|
||||
}
|
||||
|
||||
if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) {
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
final Attribute rel = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REL));
|
||||
if (rel != null) {
|
||||
link.setRel(rel.getValue());
|
||||
|
@ -260,7 +254,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
private Property property(final XMLEventReader reader, final StartElement start)
|
||||
throws XMLStreamException, EdmPrimitiveTypeException {
|
||||
|
||||
final PropertyImpl property = new PropertyImpl();
|
||||
final Property property = new Property();
|
||||
|
||||
if (propertyValueQName.equals(start.getName())) {
|
||||
// retrieve name from context
|
||||
|
@ -379,7 +373,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
}
|
||||
}
|
||||
|
||||
private void inline(final XMLEventReader reader, final StartElement start, final LinkImpl link)
|
||||
private void inline(final XMLEventReader reader, final StartElement start, final Link link)
|
||||
throws XMLStreamException, EdmPrimitiveTypeException {
|
||||
|
||||
boolean foundEndElement = false;
|
||||
|
@ -434,7 +428,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
if (!Constants.QNAME_ATOM_ELEM_FEED.equals(start.getName())) {
|
||||
return null;
|
||||
}
|
||||
final DeltaImpl delta = new DeltaImpl();
|
||||
final Delta delta = new Delta();
|
||||
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
|
||||
if (xmlBase != null) {
|
||||
delta.setBaseURI(xmlBase.getValue());
|
||||
|
@ -473,7 +467,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
} else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(event.asStartElement().getName())) {
|
||||
delta.getEntities().add(entity(reader, event.asStartElement()));
|
||||
} else if (deletedEntryQName.equals(event.asStartElement().getName())) {
|
||||
final DeletedEntityImpl deletedEntity = new DeletedEntityImpl();
|
||||
final DeletedEntity deletedEntity = new DeletedEntity();
|
||||
|
||||
final Attribute ref = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REF));
|
||||
if (ref != null) {
|
||||
|
@ -488,7 +482,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
} else if (linkQName.equals(event.asStartElement().getName())
|
||||
|| deletedLinkQName.equals(event.asStartElement().getName())) {
|
||||
|
||||
final DeltaLinkImpl link = new DeltaLinkImpl();
|
||||
final DeltaLink link = new DeltaLink();
|
||||
|
||||
final Attribute source = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_SOURCE));
|
||||
if (source != null) {
|
||||
|
@ -520,7 +514,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
return delta;
|
||||
}
|
||||
|
||||
private void properties(final XMLEventReader reader, final StartElement start, final EntityImpl entity)
|
||||
private void properties(final XMLEventReader reader, final StartElement start, final Entity entity)
|
||||
throws XMLStreamException, EdmPrimitiveTypeException {
|
||||
|
||||
final Map<String, List<Annotation>> annotations = new HashMap<String, List<Annotation>>();
|
||||
|
@ -557,7 +551,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
private Annotation annotation(final XMLEventReader reader, final StartElement start)
|
||||
throws XMLStreamException, EdmPrimitiveTypeException {
|
||||
|
||||
final Annotation annotation = new AnnotationImpl();
|
||||
final Annotation annotation = new Annotation();
|
||||
|
||||
annotation.setTerm(start.getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_TERM)).getValue());
|
||||
valuable(annotation, reader, start);
|
||||
|
@ -565,8 +559,8 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
return annotation;
|
||||
}
|
||||
|
||||
private EntityImpl entityRef(final StartElement start) throws XMLStreamException {
|
||||
final EntityImpl entity = new EntityImpl();
|
||||
private Entity entityRef(final StartElement start) throws XMLStreamException {
|
||||
final Entity entity = new Entity();
|
||||
|
||||
final Attribute entityRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
|
||||
if (entityRefId != null) {
|
||||
|
@ -578,11 +572,11 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
|
||||
private Entity entity(final XMLEventReader reader, final StartElement start)
|
||||
throws XMLStreamException, EdmPrimitiveTypeException {
|
||||
final EntityImpl entity;
|
||||
final Entity entity;
|
||||
if (entryRefQName.equals(start.getName())) {
|
||||
entity = entityRef(start);
|
||||
} else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(start.getName())) {
|
||||
entity = new EntityImpl();
|
||||
entity = new Entity();
|
||||
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
|
||||
if (xmlBase != null) {
|
||||
entity.setBaseURI(xmlBase.getValue());
|
||||
|
@ -612,7 +606,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
entity.setType(new EdmTypeInfo.Builder().setTypeExpression(term.getValue()).build().internal());
|
||||
}
|
||||
} else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) {
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
final Attribute rel = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REL));
|
||||
if (rel != null) {
|
||||
link.setRel(rel.getValue());
|
||||
|
@ -740,7 +734,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
if (!Constants.QNAME_ATOM_ELEM_FEED.equals(start.getName())) {
|
||||
return null;
|
||||
}
|
||||
final EntitySetImpl entitySet = new EntitySetImpl();
|
||||
final EntitySet entitySet = new EntitySet();
|
||||
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
|
||||
if (xmlBase != null) {
|
||||
entitySet.setBaseURI(xmlBase.getValue());
|
||||
|
|
|
@ -31,6 +31,7 @@ import javax.xml.stream.XMLStreamWriter;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.data.AbstractODataObject;
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
|
@ -47,10 +48,6 @@ import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
|||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializer;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
import org.apache.olingo.commons.core.data.AbstractODataObject;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
|
||||
|
||||
|
@ -288,9 +285,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
}
|
||||
writer.writeEndElement();
|
||||
|
||||
if (entity instanceof AbstractODataObject) {
|
||||
common(writer, (AbstractODataObject) entity);
|
||||
}
|
||||
common(writer, entity);
|
||||
|
||||
if (serverMode) {
|
||||
if (entity.getEditLink() != null) {
|
||||
|
@ -416,9 +411,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
writer.writeEndElement();
|
||||
}
|
||||
|
||||
if (entitySet instanceof AbstractODataObject) {
|
||||
common(writer, (AbstractODataObject) entitySet);
|
||||
}
|
||||
common(writer, entitySet);
|
||||
|
||||
for (Entity entity : entitySet.getEntities()) {
|
||||
if (entity.getType() == null && entity.getProperties().isEmpty()) {
|
||||
|
@ -433,14 +426,14 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
|
||||
if (serverMode) {
|
||||
if (entitySet.getNext() != null) {
|
||||
final LinkImpl next = new LinkImpl();
|
||||
final Link next = new Link();
|
||||
next.setRel(Constants.NEXT_LINK_REL);
|
||||
next.setHref(entitySet.getNext().toASCIIString());
|
||||
|
||||
links(writer, Collections.<Link> singletonList(next));
|
||||
}
|
||||
if (entitySet.getDeltaLink() != null) {
|
||||
final LinkImpl next = new LinkImpl();
|
||||
final Link next = new Link();
|
||||
next.setRel(Constants.NS_DELTA_LINK_REL);
|
||||
next.setHref(entitySet.getDeltaLink().toASCIIString());
|
||||
|
||||
|
@ -559,10 +552,10 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
final ContextURL contextURL = ContextURLParser.parse(container.getContextURL());
|
||||
String base = contextURL.getServiceRoot().toASCIIString();
|
||||
if (container.getPayload() instanceof EntitySet) {
|
||||
((EntitySetImpl) container.getPayload()).setBaseURI(base);
|
||||
((EntitySet) container.getPayload()).setBaseURI(base);
|
||||
}
|
||||
if (container.getPayload() instanceof Entity) {
|
||||
((EntityImpl) container.getPayload()).setBaseURI(base);
|
||||
((Entity) container.getPayload()).setBaseURI(base);
|
||||
}
|
||||
|
||||
writer.writeAttribute(namespaceMetadata, Constants.CONTEXT,
|
||||
|
|
|
@ -25,12 +25,11 @@ import java.net.URI;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
import org.apache.olingo.commons.api.data.DeletedEntity;
|
||||
import org.apache.olingo.commons.api.data.Delta;
|
||||
import org.apache.olingo.commons.api.data.DeltaLink;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
|
||||
import org.apache.olingo.commons.core.data.DeletedEntityImpl;
|
||||
import org.apache.olingo.commons.core.data.DeltaImpl;
|
||||
import org.apache.olingo.commons.core.data.DeltaLinkImpl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
@ -48,7 +47,7 @@ public class JsonDeltaDeserializer extends JsonDeserializer {
|
|||
|
||||
final ObjectNode tree = parser.getCodec().readTree(parser);
|
||||
|
||||
final DeltaImpl delta = new DeltaImpl();
|
||||
final Delta delta = new Delta();
|
||||
|
||||
final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ?
|
||||
URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null;
|
||||
|
@ -77,11 +76,11 @@ public class JsonDeltaDeserializer extends JsonDeserializer {
|
|||
if (itemContextURL == null || itemContextURL.isEntity()) {
|
||||
delta.getEntities().add(entityDeserializer.doDeserialize(item.traverse(parser.getCodec())).getPayload());
|
||||
} else if (itemContextURL.isDeltaDeletedEntity()) {
|
||||
delta.getDeletedEntities().add(parser.getCodec().treeToValue(item, DeletedEntityImpl.class));
|
||||
delta.getDeletedEntities().add(parser.getCodec().treeToValue(item, DeletedEntity.class));
|
||||
} else if (itemContextURL.isDeltaLink()) {
|
||||
delta.getAddedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class));
|
||||
delta.getAddedLinks().add(parser.getCodec().treeToValue(item, DeltaLink.class));
|
||||
} else if (itemContextURL.isDeltaDeletedLink()) {
|
||||
delta.getDeletedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class));
|
||||
delta.getDeletedLinks().add(parser.getCodec().treeToValue(item, DeltaLink.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.olingo.commons.api.data.Annotation;
|
|||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Linked;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
|
@ -51,11 +52,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
|||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.api.serialization.ODataDeserializer;
|
||||
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
|
||||
import org.apache.olingo.commons.core.data.AnnotationImpl;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
|
@ -96,7 +92,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
protected String setInline(final String name, final String suffix, final JsonNode tree,
|
||||
final ObjectCodec codec, final LinkImpl link) throws IOException {
|
||||
final ObjectCodec codec, final Link link) throws IOException {
|
||||
|
||||
final String entityNamePrefix = name.substring(0, name.indexOf(suffix));
|
||||
if (tree.has(entityNamePrefix)) {
|
||||
|
@ -110,7 +106,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
} else if (inline instanceof ArrayNode) {
|
||||
link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
|
||||
|
||||
final EntitySet entitySet = new EntitySetImpl();
|
||||
final EntitySet entitySet = new EntitySet();
|
||||
for (final Iterator<JsonNode> entries = inline.elements(); entries.hasNext();) {
|
||||
entitySet.getEntities().add(entityDeserializer.doDeserialize(entries.next().traverse(codec)).getPayload());
|
||||
}
|
||||
|
@ -134,7 +130,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
final JsonNode tree, final ObjectCodec codec) throws IOException {
|
||||
|
||||
if (field.getKey().endsWith(Constants.JSON_NAVIGATION_LINK)) {
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
link.setTitle(getTitle(field));
|
||||
link.setRel(Constants.NS_NAVIGATION_LINK_REL + getTitle(field));
|
||||
|
||||
|
@ -148,7 +144,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
toRemove.add(field.getKey());
|
||||
toRemove.add(setInline(field.getKey(), Constants.JSON_NAVIGATION_LINK, tree, codec, link));
|
||||
} else if (field.getKey().endsWith(Constants.JSON_ASSOCIATION_LINK)) {
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
link.setTitle(getTitle(field));
|
||||
link.setRel(Constants.NS_ASSOCIATION_LINK_REL + getTitle(field));
|
||||
link.setHref(field.getValue().textValue());
|
||||
|
@ -168,7 +164,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
if (field.getValue().isValueNode()) {
|
||||
final String suffix = field.getKey().replaceAll("^.*@", "@");
|
||||
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
link.setTitle(getTitle(field));
|
||||
link.setRel(Constants.NS_NAVIGATION_LINK_REL + getTitle(field));
|
||||
link.setHref(field.getValue().textValue());
|
||||
|
@ -180,7 +176,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
for (final Iterator<JsonNode> itor = field.getValue().elements(); itor.hasNext();) {
|
||||
final JsonNode node = itor.next();
|
||||
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
link.setTitle(getTitle(field));
|
||||
link.setRel(Constants.NS_NAVIGATION_LINK_REL + getTitle(field));
|
||||
link.setHref(node.asText());
|
||||
|
@ -243,7 +239,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
final Matcher customAnnotation = CUSTOM_ANNOTATION.matcher(field.getKey());
|
||||
|
||||
if (field.getKey().charAt(0) == '@') {
|
||||
final Annotation entityAnnot = new AnnotationImpl();
|
||||
final Annotation entityAnnot = new Annotation();
|
||||
entityAnnot.setTerm(field.getKey().substring(1));
|
||||
|
||||
value(entityAnnot, field.getValue(), codec);
|
||||
|
@ -253,11 +249,11 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
} else if (type == null && field.getKey().endsWith(getJSONAnnotation(Constants.JSON_TYPE))) {
|
||||
type = field.getValue().asText();
|
||||
} else if (annotation == null && customAnnotation.matches() && !"odata".equals(customAnnotation.group(2))) {
|
||||
annotation = new AnnotationImpl();
|
||||
annotation = new Annotation();
|
||||
annotation.setTerm(customAnnotation.group(2) + "." + customAnnotation.group(3));
|
||||
value(annotation, field.getValue(), codec);
|
||||
} else {
|
||||
final PropertyImpl property = new PropertyImpl();
|
||||
final Property property = new Property();
|
||||
property.setName(field.getKey());
|
||||
property.setType(type == null
|
||||
? null
|
||||
|
@ -289,7 +285,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
private Object fromComplex(final ObjectNode node, final ObjectCodec codec)
|
||||
throws IOException, EdmPrimitiveTypeException {
|
||||
|
||||
final ComplexValue complexValue = new ComplexValueImpl();
|
||||
final ComplexValue complexValue = new ComplexValue();
|
||||
final Set<String> toRemove = new HashSet<String>();
|
||||
for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
|
||||
final Map.Entry<String, JsonNode> field = itor.next();
|
||||
|
|
|
@ -38,9 +38,6 @@ import org.apache.olingo.commons.api.data.ResWrap;
|
|||
import org.apache.olingo.commons.api.domain.ODataLinkType;
|
||||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.core.data.AnnotationImpl;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
|
@ -67,7 +64,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
|
|||
throw new JsonParseException("Expected OData Entity, found EntitySet", parser.getCurrentLocation());
|
||||
}
|
||||
|
||||
final EntityImpl entity = new EntityImpl();
|
||||
final Entity entity = new Entity();
|
||||
|
||||
final URI contextURL;
|
||||
if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
|
||||
|
@ -108,7 +105,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
|
|||
}
|
||||
|
||||
if (tree.hasNonNull(Constants.JSON_READ_LINK)) {
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
link.setRel(Constants.SELF_LINK_REL);
|
||||
link.setHref(tree.get(Constants.JSON_READ_LINK).textValue());
|
||||
entity.setSelfLink(link);
|
||||
|
@ -117,7 +114,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
|
|||
}
|
||||
|
||||
if (tree.hasNonNull(Constants.JSON_EDIT_LINK)) {
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
if (serverMode) {
|
||||
link.setRel(Constants.EDIT_LINK_REL);
|
||||
}
|
||||
|
@ -153,7 +150,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
|
|||
|
||||
links(field, entity, toRemove, tree, parser.getCodec());
|
||||
if (field.getKey().endsWith(getJSONAnnotation(Constants.JSON_MEDIA_EDIT_LINK))) {
|
||||
final LinkImpl link = new LinkImpl();
|
||||
final Link link = new Link();
|
||||
link.setTitle(getTitle(field));
|
||||
link.setRel(Constants.NS_MEDIA_EDIT_LINK_REL + getTitle(field));
|
||||
link.setHref(field.getValue().textValue());
|
||||
|
@ -188,7 +185,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
|
|||
|
||||
toRemove.add(field.getKey());
|
||||
} else if (customAnnotation.matches() && !"odata".equals(customAnnotation.group(2))) {
|
||||
final Annotation annotation = new AnnotationImpl();
|
||||
final Annotation annotation = new Annotation();
|
||||
annotation.setTerm(customAnnotation.group(2) + "." + customAnnotation.group(3));
|
||||
try {
|
||||
value(annotation, field.getValue(), parser.getCodec());
|
||||
|
|
|
@ -29,8 +29,6 @@ import org.apache.olingo.commons.api.data.Annotation;
|
|||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.core.data.AnnotationImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
@ -55,7 +53,7 @@ public class JsonEntitySetDeserializer extends JsonDeserializer {
|
|||
return null;
|
||||
}
|
||||
|
||||
final EntitySetImpl entitySet = new EntitySetImpl();
|
||||
final EntitySet entitySet = new EntitySet();
|
||||
|
||||
URI contextURL;
|
||||
if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
|
||||
|
@ -105,7 +103,7 @@ public class JsonEntitySetDeserializer extends JsonDeserializer {
|
|||
for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
|
||||
final Map.Entry<String, JsonNode> field = itor.next();
|
||||
if (field.getKey().charAt(0) == '@') {
|
||||
final Annotation annotation = new AnnotationImpl();
|
||||
final Annotation annotation = new Annotation();
|
||||
annotation.setTerm(field.getKey().substring(1));
|
||||
|
||||
try {
|
||||
|
|
|
@ -30,8 +30,6 @@ import org.apache.olingo.commons.api.data.Property;
|
|||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.core.data.AnnotationImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
@ -53,7 +51,7 @@ public class JsonPropertyDeserializer extends JsonDeserializer {
|
|||
|
||||
final String metadataETag;
|
||||
final URI contextURL;
|
||||
final PropertyImpl property = new PropertyImpl();
|
||||
final Property property = new Property();
|
||||
|
||||
if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) {
|
||||
metadataETag = tree.get(Constants.JSON_METADATA_ETAG).textValue();
|
||||
|
@ -99,7 +97,7 @@ public class JsonPropertyDeserializer extends JsonDeserializer {
|
|||
for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
|
||||
final Map.Entry<String, JsonNode> field = itor.next();
|
||||
if (field.getKey().charAt(0) == '@') {
|
||||
final Annotation annotation = new AnnotationImpl();
|
||||
final Annotation annotation = new Annotation();
|
||||
annotation.setTerm(field.getKey().substring(1));
|
||||
|
||||
try {
|
||||
|
|
|
@ -205,13 +205,13 @@ public class JsonSerializer implements ODataSerializer {
|
|||
}
|
||||
|
||||
protected void serverLinks(final Linked linked, final JsonGenerator jgen)
|
||||
throws IOException, EdmPrimitiveTypeException {
|
||||
throws IOException, EdmPrimitiveTypeException {
|
||||
if (linked instanceof Entity) {
|
||||
for (Link link : ((Entity) linked).getMediaEditLinks()) {
|
||||
if (StringUtils.isNotBlank(link.getHref())) {
|
||||
jgen.writeStringField(
|
||||
link.getTitle() + StringUtils.prependIfMissing(Constants.JSON_MEDIA_EDIT_LINK, "@"),
|
||||
link.getHref());
|
||||
link.getTitle() + StringUtils.prependIfMissing(Constants.JSON_MEDIA_EDIT_LINK, "@"),
|
||||
link.getHref());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,8 +219,8 @@ public class JsonSerializer implements ODataSerializer {
|
|||
for (Link link : linked.getAssociationLinks()) {
|
||||
if (StringUtils.isNotBlank(link.getHref())) {
|
||||
jgen.writeStringField(
|
||||
link.getTitle() + Constants.JSON_ASSOCIATION_LINK,
|
||||
link.getHref());
|
||||
link.getTitle() + Constants.JSON_ASSOCIATION_LINK,
|
||||
link.getHref());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,8 +231,8 @@ public class JsonSerializer implements ODataSerializer {
|
|||
|
||||
if (StringUtils.isNotBlank(link.getHref())) {
|
||||
jgen.writeStringField(
|
||||
link.getTitle() + Constants.JSON_NAVIGATION_LINK,
|
||||
link.getHref());
|
||||
link.getTitle() + Constants.JSON_NAVIGATION_LINK,
|
||||
link.getHref());
|
||||
}
|
||||
|
||||
if (link.getInlineEntity() != null) {
|
||||
|
@ -359,8 +359,8 @@ public class JsonSerializer implements ODataSerializer {
|
|||
|
||||
String type = valuable.getType();
|
||||
if ((!valuable.isCollection() &&
|
||||
StringUtils.isBlank(type) &&
|
||||
valuable.isPrimitive()) || valuable.isNull()) {
|
||||
StringUtils.isBlank(type) &&
|
||||
valuable.isPrimitive()) || valuable.isNull()) {
|
||||
type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString();
|
||||
}
|
||||
if (StringUtils.isNotBlank(type) && format != ODataFormat.JSON_NO_METADATA) {
|
||||
|
@ -370,10 +370,8 @@ public class JsonSerializer implements ODataSerializer {
|
|||
}
|
||||
}
|
||||
|
||||
if (valuable instanceof Annotatable) {
|
||||
for (Annotation annotation : ((Annotatable) valuable).getAnnotations()) {
|
||||
valuable(jgen, annotation, name + "@" + annotation.getTerm());
|
||||
}
|
||||
for (Annotation annotation : ((Annotatable) valuable).getAnnotations()) {
|
||||
valuable(jgen, annotation, name + "@" + annotation.getTerm());
|
||||
}
|
||||
|
||||
jgen.writeFieldName(name);
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.apache.olingo.server.api;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.provider.EdmProvider;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
|
@ -99,5 +101,17 @@ public abstract class OData {
|
|||
*/
|
||||
public abstract UriHelper createUriHelper();
|
||||
|
||||
/**
|
||||
* Creates a new deserializer object for reading content in the specified format.
|
||||
* Deserializer are used in Processor implementations.
|
||||
*
|
||||
* @param format any format supported by Olingo (XML, JSON ...)
|
||||
*/
|
||||
public abstract ODataDeserializer createDeserializer(ODataFormat format) throws DeserializerException;
|
||||
|
||||
/**
|
||||
* @param kind
|
||||
* @return a {@link EdmPrimitiveType} instance for the type kind
|
||||
*/
|
||||
public abstract EdmPrimitiveType createPrimitiveTypeInstance(EdmPrimitiveTypeKind kind);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,11 @@ package org.apache.olingo.server.core;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.provider.EdmProvider;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataHttpHandler;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
|
@ -105,4 +108,9 @@ public class ODataImpl extends OData {
|
|||
|
||||
return serializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveType createPrimitiveTypeInstance(EdmPrimitiveTypeKind kind) {
|
||||
return EdmPrimitiveTypeFactory.getInstance(kind);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,12 +50,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
|||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.ParameterImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerResult;
|
||||
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
||||
|
@ -80,13 +74,13 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
private static final String ODATA_CONTROL_INFORMATION_PREFIX = "@odata.";
|
||||
|
||||
@Override
|
||||
public DeserializerResult entityCollection(InputStream stream, EdmEntityType edmEntityType)
|
||||
public DeserializerResult entityCollection(InputStream stream, EdmEntityType edmEntityType)
|
||||
throws DeserializerException {
|
||||
try {
|
||||
final ObjectNode tree = parseJsonTree(stream);
|
||||
|
||||
|
||||
return DeserializerResultImpl.with().entityCollection(consumeEntitySetNode(edmEntityType, tree, null))
|
||||
.build();
|
||||
.build();
|
||||
} catch (JsonParseException e) {
|
||||
throw new DeserializerException("An JsonParseException occurred", e,
|
||||
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
||||
|
@ -98,9 +92,9 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
}
|
||||
|
||||
private EntitySet consumeEntitySetNode(EdmEntityType edmEntityType, final ObjectNode tree,
|
||||
private EntitySet consumeEntitySetNode(EdmEntityType edmEntityType, final ObjectNode tree,
|
||||
final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
||||
EntitySetImpl entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
// Consume entities
|
||||
JsonNode jsonNode = tree.get(Constants.VALUE);
|
||||
|
@ -137,7 +131,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
return entitySet;
|
||||
}
|
||||
|
||||
private List<Entity> consumeEntitySetArray(EdmEntityType edmEntityType, JsonNode jsonNode,
|
||||
private List<Entity> consumeEntitySetArray(EdmEntityType edmEntityType, JsonNode jsonNode,
|
||||
final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
||||
List<Entity> entities = new ArrayList<Entity>();
|
||||
for (JsonNode arrayElement : jsonNode) {
|
||||
|
@ -156,10 +150,10 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
try {
|
||||
final ObjectNode tree = parseJsonTree(stream);
|
||||
final ExpandTreeBuilderImpl expandBuilder = new ExpandTreeBuilderImpl();
|
||||
|
||||
|
||||
return DeserializerResultImpl.with().entity(consumeEntityNode(edmEntityType, tree, expandBuilder))
|
||||
.expandOption(expandBuilder.build())
|
||||
.build();
|
||||
.expandOption(expandBuilder.build())
|
||||
.build();
|
||||
|
||||
} catch (JsonParseException e) {
|
||||
throw new DeserializerException("An JsonParseException occurred", e,
|
||||
|
@ -173,9 +167,9 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
|
||||
}
|
||||
|
||||
private Entity consumeEntityNode(EdmEntityType edmEntityType, final ObjectNode tree,
|
||||
private Entity consumeEntityNode(EdmEntityType edmEntityType, final ObjectNode tree,
|
||||
final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
||||
EntityImpl entity = new EntityImpl();
|
||||
Entity entity = new Entity();
|
||||
entity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
|
||||
|
||||
// Check and consume all Properties
|
||||
|
@ -193,7 +187,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DeserializerResult actionParameters(InputStream stream, final EdmAction edmAction)
|
||||
public DeserializerResult actionParameters(InputStream stream, final EdmAction edmAction)
|
||||
throws DeserializerException {
|
||||
try {
|
||||
ObjectNode tree = parseJsonTree(stream);
|
||||
|
@ -214,7 +208,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
}
|
||||
|
||||
private ObjectNode parseJsonTree(InputStream stream)
|
||||
private ObjectNode parseJsonTree(InputStream stream)
|
||||
throws IOException, JsonParseException, JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
|
||||
|
@ -232,7 +226,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
for (final String name : parameterNames) {
|
||||
final EdmParameter edmParameter = edmAction.getParameter(name);
|
||||
ParameterImpl parameter = new ParameterImpl();
|
||||
Parameter parameter = new Parameter();
|
||||
parameter.setName(name);
|
||||
JsonNode jsonNode = node.get(name);
|
||||
|
||||
|
@ -281,7 +275,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
* @throws DeserializerException if an exception during consummation occurs
|
||||
*/
|
||||
private void consumeRemainingJsonNodeFields(final EdmEntityType edmEntityType, final ObjectNode node,
|
||||
final EntityImpl entity) throws DeserializerException {
|
||||
final Entity entity) throws DeserializerException {
|
||||
final List<String> toRemove = new ArrayList<String>();
|
||||
Iterator<Entry<String, JsonNode>> fieldsIterator = node.fields();
|
||||
while (fieldsIterator.hasNext()) {
|
||||
|
@ -304,7 +298,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
private void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node,
|
||||
final EntityImpl entity) throws DeserializerException {
|
||||
final Entity entity) throws DeserializerException {
|
||||
List<String> propertyNames = edmEntityType.getPropertyNames();
|
||||
for (String propertyName : propertyNames) {
|
||||
JsonNode jsonNode = node.get(propertyName);
|
||||
|
@ -326,7 +320,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
private void consumeExpandedNavigationProperties(final EdmEntityType edmEntityType, final ObjectNode node,
|
||||
final EntityImpl entity, final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
||||
final Entity entity, final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
||||
List<String> navigationPropertyNames = edmEntityType.getNavigationPropertyNames();
|
||||
for (String navigationPropertyName : navigationPropertyNames) {
|
||||
// read expanded navigation property
|
||||
|
@ -339,22 +333,22 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, navigationPropertyName);
|
||||
}
|
||||
|
||||
LinkImpl link = new LinkImpl();
|
||||
Link link = new Link();
|
||||
link.setTitle(navigationPropertyName);
|
||||
final ExpandTreeBuilder childExpandBuilder = (expandBuilder != null) ?
|
||||
expandBuilder.expand(edmNavigationProperty) : null;
|
||||
final ExpandTreeBuilder childExpandBuilder = (expandBuilder != null) ?
|
||||
expandBuilder.expand(edmNavigationProperty) : null;
|
||||
if (jsonNode.isArray() && edmNavigationProperty.isCollection()) {
|
||||
link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
|
||||
EntitySetImpl inlineEntitySet = new EntitySetImpl();
|
||||
inlineEntitySet.getEntities().addAll(consumeEntitySetArray(edmNavigationProperty.getType(), jsonNode,
|
||||
childExpandBuilder));
|
||||
EntitySet inlineEntitySet = new EntitySet();
|
||||
inlineEntitySet.getEntities().addAll(consumeEntitySetArray(edmNavigationProperty.getType(), jsonNode,
|
||||
childExpandBuilder));
|
||||
link.setInlineEntitySet(inlineEntitySet);
|
||||
} else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull())
|
||||
&& !edmNavigationProperty.isCollection()) {
|
||||
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
|
||||
if (!jsonNode.isNull()) {
|
||||
Entity inlineEntity = consumeEntityNode(edmNavigationProperty.getType(), (ObjectNode) jsonNode,
|
||||
childExpandBuilder);
|
||||
Entity inlineEntity = consumeEntityNode(edmNavigationProperty.getType(), (ObjectNode) jsonNode,
|
||||
childExpandBuilder);
|
||||
link.setInlineEntity(inlineEntity);
|
||||
}
|
||||
} else {
|
||||
|
@ -377,7 +371,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
throw new DeserializerException("Invalid navigationPropertyName: " + navigationPropertyName,
|
||||
DeserializerException.MessageKeys.NAVIGATION_PROPERTY_NOT_FOUND, navigationPropertyName);
|
||||
}
|
||||
LinkImpl bindingLink = new LinkImpl();
|
||||
Link bindingLink = new Link();
|
||||
bindingLink.setTitle(navigationPropertyName);
|
||||
|
||||
if (edmNavigationProperty.isCollection()) {
|
||||
|
@ -419,7 +413,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
private Property consumePropertyNode(final String name, final EdmType type, final boolean isCollection,
|
||||
final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
|
||||
final boolean isUnicode, final EdmMapping mapping, JsonNode jsonNode) throws DeserializerException {
|
||||
Property property = new PropertyImpl();
|
||||
Property property = new Property();
|
||||
property.setName(name);
|
||||
property.setType(type.getFullQualifiedName().getFullQualifiedNameAsString());
|
||||
if (isCollection) {
|
||||
|
@ -552,7 +546,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, name);
|
||||
}
|
||||
// Even if there are no properties defined we have to give back an empty list
|
||||
ComplexValueImpl complexValue = new ComplexValueImpl();
|
||||
ComplexValue complexValue = new ComplexValue();
|
||||
EdmComplexType edmType = (EdmComplexType) type;
|
||||
// Check and consume all Properties
|
||||
for (String propertyName : edmType.getPropertyNames()) {
|
||||
|
@ -795,9 +789,9 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
JsonNode jsonNode = tree.get(Constants.VALUE);
|
||||
if (jsonNode != null) {
|
||||
if (jsonNode.isArray()) {
|
||||
ArrayNode arrayNode = (ArrayNode)jsonNode;
|
||||
ArrayNode arrayNode = (ArrayNode) jsonNode;
|
||||
Iterator<JsonNode> it = arrayNode.iterator();
|
||||
while(it.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
parsedValues.add(new URI(it.next().get(key).asText()));
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -33,8 +33,6 @@ import org.apache.olingo.commons.api.data.ContextURL;
|
|||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -44,7 +42,7 @@ public class ODataJsonSerializerTest {
|
|||
final List<ComplexValue> col = new ArrayList<ComplexValue>();
|
||||
col.add(getValues(1));
|
||||
col.add(getValues(2));
|
||||
final Property complexCollection = new PropertyImpl(null, "ComplexCol", ValueType.COLLECTION_COMPLEX, col);
|
||||
final Property complexCollection = new Property(null, "ComplexCol", ValueType.COLLECTION_COMPLEX, col);
|
||||
|
||||
final ODataJsonSerializer serializer = new ODataJsonSerializer(ODataFormat.APPLICATION_JSON);
|
||||
final ComplexSerializerOptions options = ComplexSerializerOptions.with()
|
||||
|
@ -66,9 +64,9 @@ public class ODataJsonSerializerTest {
|
|||
}
|
||||
|
||||
private ComplexValue getValues(int i) {
|
||||
ComplexValue value = new ComplexValueImpl();
|
||||
value.getValue().add(new PropertyImpl(null, "prop1", ValueType.PRIMITIVE, "test" + i));
|
||||
value.getValue().add(new PropertyImpl(null, "prop2", ValueType.PRIMITIVE, "test" + i + i));
|
||||
ComplexValue value = new ComplexValue();
|
||||
value.getValue().add(new Property(null, "prop1", ValueType.PRIMITIVE, "test" + i));
|
||||
value.getValue().add(new Property(null, "prop2", ValueType.PRIMITIVE, "test" + i + i));
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,6 +133,7 @@
|
|||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>odata-commons-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
/*******************************************************************************
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
******************************************************************************/
|
||||
package org.apache.olingo.server.tecsvc;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* Encodes a Java String (in its internal UTF-16 encoding) into its
|
||||
* percent-encoded UTF-8 representation according to
|
||||
* <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>
|
||||
* (with consideration of its predecessor RFC 2396).
|
||||
*
|
||||
*/
|
||||
public class Encoder {
|
||||
|
||||
//TODO: Should we really copy this class?
|
||||
|
||||
/**
|
||||
* Encodes a Java String (in its internal UTF-16 encoding) into its
|
||||
* percent-encoded UTF-8 representation according to
|
||||
* <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>,
|
||||
* suitable for parts of an OData path segment.
|
||||
* @param value the Java String
|
||||
* @return the encoded String
|
||||
*/
|
||||
public static String encode(final String value) {
|
||||
return encoder.encodeInternal(value);
|
||||
}
|
||||
|
||||
// OData has special handling for "'", so we allow that to remain unencoded.
|
||||
// Other sub-delims not used neither by JAX-RS nor by OData could be added
|
||||
// if the encoding is considered to be too aggressive.
|
||||
// RFC 3986 would also allow the gen-delims ":" and "@" to appear literally
|
||||
// in path-segment parts.
|
||||
private static final String ODATA_UNENCODED = "'";
|
||||
|
||||
// Character classes from RFC 3986
|
||||
private final static String UNRESERVED = "-._~"; // + ALPHA + DIGIT
|
||||
// RFC 3986 says: "For consistency, URI producers and normalizers should
|
||||
// use uppercase hexadecimal digits for all percent-encodings."
|
||||
private final static String[] hex = { "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", "%0A",
|
||||
"%0B", "%0C", "%0D", "%0E", "%0F", "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17", "%18", "%19", "%1A",
|
||||
"%1B", "%1C", "%1D", "%1E", "%1F", "%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27", "%28", "%29", "%2A",
|
||||
"%2B", "%2C", "%2D", "%2E", "%2F", "%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37", "%38", "%39", "%3A",
|
||||
"%3B", "%3C", "%3D", "%3E", "%3F", "%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47", "%48", "%49", "%4A",
|
||||
"%4B", "%4C", "%4D", "%4E", "%4F", "%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57", "%58", "%59", "%5A",
|
||||
"%5B", "%5C", "%5D", "%5E", "%5F", "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67", "%68", "%69", "%6A",
|
||||
"%6B", "%6C", "%6D", "%6E", "%6F", "%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77", "%78", "%79", "%7A",
|
||||
"%7B", "%7C", "%7D", "%7E", "%7F", "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87", "%88",
|
||||
"%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F", "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98",
|
||||
"%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F", "%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7", "%A8",
|
||||
"%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF", "%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7", "%B8",
|
||||
"%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF", "%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7", "%C8",
|
||||
"%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF", "%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7", "%D8",
|
||||
"%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF", "%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7", "%E8",
|
||||
"%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF", "%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7", "%F8",
|
||||
"%F9", "%FA", "%FB", "%FC", "%FD", "%FE", "%FF" };
|
||||
|
||||
private static final Encoder encoder = new Encoder(ODATA_UNENCODED);
|
||||
|
||||
/** characters to remain unencoded in addition to {@link #UNRESERVED} */
|
||||
private final String unencoded;
|
||||
|
||||
private Encoder(final String unencoded) {
|
||||
this.unencoded = unencoded == null ? "" : unencoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns the percent-encoded UTF-8 representation of a String.</p>
|
||||
* <p>In order to avoid producing percent-encoded CESU-8 (as described in
|
||||
* the Unicode Consortium's <a href="http://www.unicode.org/reports/tr26/">
|
||||
* Technical Report #26</a>), this is done in two steps:
|
||||
* <ol>
|
||||
* <li>Re-encode the characters from their Java-internal UTF-16 representations
|
||||
* into their UTF-8 representations.</li>
|
||||
* <li>Percent-encode each of the bytes in the UTF-8 representation.
|
||||
* This is possible on byte level because all characters that do not have
|
||||
* a <code>%xx</code> representation are represented in one byte in UTF-8.</li>
|
||||
* </ol></p>
|
||||
* @param input input String
|
||||
* @return encoded representation
|
||||
*/
|
||||
private String encodeInternal(final String input) {
|
||||
StringBuilder resultStr = new StringBuilder();
|
||||
|
||||
try {
|
||||
for (byte utf8Byte : input.getBytes("UTF-8")) {
|
||||
final char character = (char) utf8Byte;
|
||||
if (isUnreserved(character)) {
|
||||
resultStr.append(character);
|
||||
} else if (isUnencoded(character)) {
|
||||
resultStr.append(character);
|
||||
} else if (utf8Byte >= 0) {
|
||||
resultStr.append(hex[utf8Byte]);
|
||||
} else {
|
||||
// case UTF-8 continuation byte
|
||||
resultStr.append(hex[256 + utf8Byte]); // index adjusted for the usage of signed bytes
|
||||
}
|
||||
}
|
||||
} catch (final UnsupportedEncodingException e) { // should never happen; UTF-8 is always there
|
||||
return null;
|
||||
}
|
||||
return resultStr.toString();
|
||||
}
|
||||
|
||||
private static boolean isUnreserved(final char character) {
|
||||
return 'A' <= character && character <= 'Z' // case A..Z
|
||||
|| 'a' <= character && character <= 'z' // case a..z
|
||||
|| '0' <= character && character <= '9' // case 0..9
|
||||
|| UNRESERVED.indexOf(character) >= 0;
|
||||
}
|
||||
|
||||
private boolean isUnencoded(final char character) {
|
||||
return unencoded.indexOf(character) >= 0;
|
||||
}
|
||||
}
|
|
@ -36,11 +36,6 @@ import org.apache.olingo.commons.api.data.Link;
|
|||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkType;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
|
||||
public class DataCreator {
|
||||
|
||||
|
@ -64,19 +59,19 @@ public class DataCreator {
|
|||
data.put("ESServerSidePaging", createESServerSidePaging());
|
||||
|
||||
// No data available but to allow an insert operation create empty EntitySets
|
||||
data.put("ESAllNullable", new EntitySetImpl());
|
||||
data.put("ESMixEnumDefCollComp", new EntitySetImpl());
|
||||
data.put("ESTwoBase", new EntitySetImpl());
|
||||
data.put("ESBaseTwoKeyNav", new EntitySetImpl());
|
||||
data.put("ESBaseTwoKeyTwoPrim", new EntitySetImpl());
|
||||
data.put("ESTwoKeyTwoPrim", new EntitySetImpl());
|
||||
data.put("ESCompCollAllPrim", new EntitySetImpl());
|
||||
data.put("ESKeyTwoKeyComp", new EntitySetImpl());
|
||||
data.put("ESFourKeyAlias", new EntitySetImpl());
|
||||
data.put("ESBase", new EntitySetImpl());
|
||||
data.put("ESTwoBaseTwoKeyTwoPrim", new EntitySetImpl());
|
||||
data.put("ESInvisible", new EntitySetImpl());
|
||||
data.put("ESCompMixPrimCollComp", new EntitySetImpl());
|
||||
data.put("ESAllNullable", new EntitySet());
|
||||
data.put("ESMixEnumDefCollComp", new EntitySet());
|
||||
data.put("ESTwoBase", new EntitySet());
|
||||
data.put("ESBaseTwoKeyNav", new EntitySet());
|
||||
data.put("ESBaseTwoKeyTwoPrim", new EntitySet());
|
||||
data.put("ESTwoKeyTwoPrim", new EntitySet());
|
||||
data.put("ESCompCollAllPrim", new EntitySet());
|
||||
data.put("ESKeyTwoKeyComp", new EntitySet());
|
||||
data.put("ESFourKeyAlias", new EntitySet());
|
||||
data.put("ESBase", new EntitySet());
|
||||
data.put("ESTwoBaseTwoKeyTwoPrim", new EntitySet());
|
||||
data.put("ESInvisible", new EntitySet());
|
||||
data.put("ESCompMixPrimCollComp", new EntitySet());
|
||||
|
||||
linkESTwoPrim(data);
|
||||
linkESAllPrim(data);
|
||||
|
@ -89,10 +84,10 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
private EntitySet createESServerSidePaging() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
for (int i = 1; i <= 503; i++) {
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", i))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", i))
|
||||
.addProperty(createPrimitive("PropertyString", "Number:" + i)));
|
||||
}
|
||||
|
||||
|
@ -100,7 +95,7 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
private EntitySet createESKeyNav() {
|
||||
final EntitySet entitySet = new EntitySetImpl();
|
||||
final EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(createETKeyNavEntity(1, "I am String Property 1"));
|
||||
entitySet.getEntities().add(createETKeyNavEntity(2, "I am String Property 2"));
|
||||
|
@ -111,7 +106,7 @@ public class DataCreator {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Entity createETKeyNavEntity(int propertyInt16, String propertyString) {
|
||||
return new EntityImpl().addProperty(createPrimitive("PropertyInt16", propertyInt16))
|
||||
return new Entity().addProperty(createPrimitive("PropertyInt16", propertyInt16))
|
||||
.addProperty(createPrimitive("PropertyString", propertyString))
|
||||
.addProperty(createComplex("PropertyCompNav", createPrimitive("PropertyInt16", 1)))
|
||||
.addProperty(createKeyNavAllPrimComplexValue("PropertyCompAllPrim")).addProperty(
|
||||
|
@ -129,7 +124,7 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
private EntitySet createESTwoKeyNav() {
|
||||
final EntitySet entitySet = new EntitySetImpl();
|
||||
final EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(createESTwoKeyNavEntity(1, "1"));
|
||||
entitySet.getEntities().add(createESTwoKeyNavEntity(1, "2"));
|
||||
|
@ -141,7 +136,7 @@ public class DataCreator {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Entity createESTwoKeyNavEntity(int propertyInt16, String propertyString) {
|
||||
return new EntityImpl().addProperty(createPrimitive("PropertyInt16", propertyInt16))
|
||||
return new Entity().addProperty(createPrimitive("PropertyInt16", propertyInt16))
|
||||
.addProperty(createPrimitive("PropertyString", propertyString)).addProperty(
|
||||
createComplex("PropertyComp", createPrimitive("PropertyInt16", 11),
|
||||
createComplex("PropertyComp", createPrimitive("PropertyString", "StringValue"),
|
||||
|
@ -180,9 +175,9 @@ public class DataCreator {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private EntitySet createESCompCollComp() {
|
||||
final EntitySet entitySet = new EntitySetImpl();
|
||||
final EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
|
||||
.addProperty(createComplex("PropertyComp", createComplexCollection("CollPropertyComp", Arrays
|
||||
.asList(createPrimitive("PropertyInt16", 555),
|
||||
createPrimitive("PropertyString", "1 Test Complex in Complex Property")), Arrays
|
||||
|
@ -191,7 +186,7 @@ public class DataCreator {
|
|||
.asList(createPrimitive("PropertyInt16", 777),
|
||||
createPrimitive("PropertyString", "3 Test Complex in Complex Property"))))));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 12345)).addProperty(
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", 12345)).addProperty(
|
||||
createComplex("PropertyComp", createComplexCollection("CollPropertyComp", Arrays
|
||||
.asList(createPrimitive("PropertyInt16", 888),
|
||||
createPrimitive("PropertyString", "11 Test Complex in Complex Property")), Arrays
|
||||
|
@ -204,27 +199,27 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
private EntitySet createESTwoPrim() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 32766))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", 32766))
|
||||
.addProperty(createPrimitive("PropertyString", "Test String1")));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", -365))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", -365))
|
||||
.addProperty(createPrimitive("PropertyString", "Test String2")));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", -32766))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", -32766))
|
||||
.addProperty(createPrimitive("PropertyString", null)));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
|
||||
.addProperty(createPrimitive("PropertyString", "Test String4")));
|
||||
|
||||
return entitySet;
|
||||
}
|
||||
|
||||
private EntitySet createESAllPrim() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
|
||||
.addProperty(createPrimitive("PropertyString", "First Resource - positive values"))
|
||||
.addProperty(createPrimitive("PropertyBoolean", true)).addProperty(createPrimitive("PropertyByte", 255))
|
||||
.addProperty(createPrimitive("PropertySByte", Byte.MAX_VALUE))
|
||||
|
@ -239,7 +234,7 @@ public class DataCreator {
|
|||
.addProperty(createPrimitive("PropertyDuration", 6)).addProperty(createPrimitive("PropertyGuid", GUID))
|
||||
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(3, 26, 5))));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MIN_VALUE))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", Short.MIN_VALUE))
|
||||
.addProperty(createPrimitive("PropertyString", "Second Resource - negative values"))
|
||||
.addProperty(createPrimitive("PropertyBoolean", false)).addProperty(createPrimitive("PropertyByte", 0))
|
||||
.addProperty(createPrimitive("PropertySByte", Byte.MIN_VALUE))
|
||||
|
@ -255,7 +250,7 @@ public class DataCreator {
|
|||
.addProperty(createPrimitive("PropertyGuid", UUID.fromString("76543201-23ab-cdef-0123-456789dddfff")))
|
||||
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(23, 49, 14))));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 0))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", 0))
|
||||
.addProperty(createPrimitive("PropertyString", "")).addProperty(createPrimitive("PropertyBoolean", false))
|
||||
.addProperty(createPrimitive("PropertyByte", 0)).addProperty(createPrimitive("PropertySByte", 0))
|
||||
.addProperty(createPrimitive("PropertyInt32", 0)).addProperty(createPrimitive("PropertyInt64", 0))
|
||||
|
@ -272,9 +267,9 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
private EntitySet createESCompAllPrim() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
Entity entity = new EntityImpl();
|
||||
Entity entity = new Entity();
|
||||
entity.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE));
|
||||
entity.addProperty(createComplex("PropertyComp", createPrimitive("PropertyString", "First Resource - first"),
|
||||
createPrimitive("PropertyBinary",
|
||||
|
@ -289,7 +284,7 @@ public class DataCreator {
|
|||
createPrimitive("PropertySByte", Byte.MAX_VALUE), createPrimitive("PropertyTimeOfDay", getTime(1, 0, 1))));
|
||||
entitySet.getEntities().add(entity);
|
||||
|
||||
entity = new EntityImpl();
|
||||
entity = new Entity();
|
||||
entity.addProperty(createPrimitive("PropertyInt16", 7));
|
||||
entity.addProperty(createComplex("PropertyComp", createPrimitive("PropertyString", "Second Resource - second"),
|
||||
createPrimitive("PropertyBinary",
|
||||
|
@ -305,7 +300,7 @@ public class DataCreator {
|
|||
createPrimitive("PropertyTimeOfDay", getTimestamp(1, 1, 1, 7, 45, 12, 765432100))));
|
||||
entitySet.getEntities().add(entity);
|
||||
|
||||
entity = new EntityImpl();
|
||||
entity = new Entity();
|
||||
entity.addProperty(createPrimitive("PropertyInt16", 0));
|
||||
entity.addProperty(createComplex("PropertyComp", createPrimitive("PropertyString", "Third Resource - third"),
|
||||
createPrimitive("PropertyBinary",
|
||||
|
@ -324,9 +319,9 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
private EntitySet createESCollAllPrim() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 1)).addProperty(
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", 1)).addProperty(
|
||||
createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
|
||||
"Employee3@company.example"))
|
||||
.addProperty(createPrimitiveCollection("CollPropertyBoolean", true, false, true))
|
||||
|
@ -353,12 +348,12 @@ public class DataCreator {
|
|||
createPrimitiveCollection("CollPropertyTimeOfDay", getTime(4, 14, 13), getTime(23, 59, 59),
|
||||
getTime(1, 12, 33))));
|
||||
|
||||
Entity entity = new EntityImpl();
|
||||
Entity entity = new Entity();
|
||||
entity.getProperties().addAll(entitySet.getEntities().get(0).getProperties());
|
||||
entity.getProperties().set(0, createPrimitive("PropertyInt16", 2));
|
||||
entitySet.getEntities().add(entity);
|
||||
|
||||
entity = new EntityImpl();
|
||||
entity = new Entity();
|
||||
entity.getProperties().addAll(entitySet.getEntities().get(0).getProperties());
|
||||
entity.getProperties().set(0, createPrimitive("PropertyInt16", 3));
|
||||
entitySet.getEntities().add(entity);
|
||||
|
@ -372,22 +367,22 @@ public class DataCreator {
|
|||
Arrays.asList(createPrimitive("PropertyInt16", 456), createPrimitive("PropertyString", "TEST 2")),
|
||||
Arrays.asList(createPrimitive("PropertyInt16", 789), createPrimitive("PropertyString", "TEST 3")));
|
||||
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
|
||||
.addProperty(
|
||||
createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
|
||||
"Employee3@company.example")).addProperty(
|
||||
createComplex("PropertyComp", createPrimitive("PropertyInt16", 111),
|
||||
createPrimitive("PropertyString", "TEST A"))).addProperty(complexCollection));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 7)).addProperty(
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", 7)).addProperty(
|
||||
createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
|
||||
"Employee3@company.example")).addProperty(
|
||||
createComplex("PropertyComp", createPrimitive("PropertyInt16", 222),
|
||||
createPrimitive("PropertyString", "TEST B"))).addProperty(complexCollection));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 0)).addProperty(
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyInt16", 0)).addProperty(
|
||||
createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
|
||||
"Employee3@company.example")).addProperty(
|
||||
createComplex("PropertyComp", createPrimitive("PropertyInt16", 333),
|
||||
|
@ -397,9 +392,9 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
private EntitySet createESAllKey() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyString", "First"))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyString", "First"))
|
||||
.addProperty(createPrimitive("PropertyBoolean", true)).addProperty(createPrimitive("PropertyByte", 255))
|
||||
.addProperty(createPrimitive("PropertySByte", Byte.MAX_VALUE))
|
||||
.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
|
||||
|
@ -411,7 +406,7 @@ public class DataCreator {
|
|||
.addProperty(createPrimitive("PropertyDuration", 6)).addProperty(createPrimitive("PropertyGuid", GUID))
|
||||
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(2, 48, 21))));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyString", "Second"))
|
||||
entitySet.getEntities().add(new Entity().addProperty(createPrimitive("PropertyString", "Second"))
|
||||
.addProperty(createPrimitive("PropertyBoolean", true)).addProperty(createPrimitive("PropertyByte", 254))
|
||||
.addProperty(createPrimitive("PropertySByte", 124)).addProperty(createPrimitive("PropertyInt16", 32764))
|
||||
.addProperty(createPrimitive("PropertyInt32", 2147483644))
|
||||
|
@ -426,16 +421,16 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
private EntitySet createESCompComp() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
Entity entity = new EntityImpl();
|
||||
Entity entity = new Entity();
|
||||
entity.addProperty(createPrimitive("PropertyInt16", 1));
|
||||
entity.addProperty(createComplex("PropertyComp",
|
||||
createComplex("PropertyComp", createPrimitive("PropertyInt16", 123),
|
||||
createPrimitive("PropertyString", "String 1"))));
|
||||
entitySet.getEntities().add(entity);
|
||||
|
||||
entity = new EntityImpl();
|
||||
entity = new Entity();
|
||||
entity.addProperty(createPrimitive("PropertyInt16", 2));
|
||||
entity.addProperty(createComplex("PropertyComp",
|
||||
createComplex("PropertyComp", createPrimitive("PropertyInt16", 987),
|
||||
|
@ -446,24 +441,24 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
private EntitySet createESMedia() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
Entity entity = new EntityImpl().addProperty(createPrimitive("PropertyInt16", 1))
|
||||
Entity entity = new Entity().addProperty(createPrimitive("PropertyInt16", 1))
|
||||
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("darkturquoise")));
|
||||
entity.setMediaContentType("image/svg+xml");
|
||||
entitySet.getEntities().add(entity);
|
||||
|
||||
entity = new EntityImpl().addProperty(createPrimitive("PropertyInt16", 2))
|
||||
entity = new Entity().addProperty(createPrimitive("PropertyInt16", 2))
|
||||
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("royalblue")));
|
||||
entity.setMediaContentType("image/svg+xml");
|
||||
entitySet.getEntities().add(entity);
|
||||
|
||||
entity = new EntityImpl().addProperty(createPrimitive("PropertyInt16", 3))
|
||||
entity = new Entity().addProperty(createPrimitive("PropertyInt16", 3))
|
||||
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("crimson")));
|
||||
entity.setMediaContentType("image/svg+xml");
|
||||
entitySet.getEntities().add(entity);
|
||||
|
||||
entity = new EntityImpl().addProperty(createPrimitive("PropertyInt16", 4))
|
||||
entity = new Entity().addProperty(createPrimitive("PropertyInt16", 4))
|
||||
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("black")));
|
||||
entity.setMediaContentType("image/svg+xml");
|
||||
entitySet.getEntities().add(entity);
|
||||
|
@ -558,29 +553,29 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
protected static Property createPrimitive(final String name, final Object value) {
|
||||
return new PropertyImpl(null, name, ValueType.PRIMITIVE, value);
|
||||
return new Property(null, name, ValueType.PRIMITIVE, value);
|
||||
}
|
||||
|
||||
protected static Property createPrimitiveCollection(final String name, final Object... values) {
|
||||
return new PropertyImpl(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(values));
|
||||
return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(values));
|
||||
}
|
||||
|
||||
protected static Property createComplex(final String name, final Property... properties) {
|
||||
ComplexValue complexValue = new ComplexValueImpl();
|
||||
ComplexValue complexValue = new ComplexValue();
|
||||
for (final Property property : properties) {
|
||||
complexValue.getValue().add(property);
|
||||
}
|
||||
return new PropertyImpl(null, name, ValueType.COMPLEX, complexValue);
|
||||
return new Property(null, name, ValueType.COMPLEX, complexValue);
|
||||
}
|
||||
|
||||
protected static Property createComplexCollection(final String name, final List<Property>... propertiesList) {
|
||||
List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
|
||||
for (final List<Property> properties : propertiesList) {
|
||||
ComplexValue complexValue = new ComplexValueImpl();
|
||||
ComplexValue complexValue = new ComplexValue();
|
||||
complexValue.getValue().addAll(properties);
|
||||
complexCollection.add(complexValue);
|
||||
}
|
||||
return new PropertyImpl(null, name, ValueType.COLLECTION_COMPLEX, complexCollection);
|
||||
return new Property(null, name, ValueType.COLLECTION_COMPLEX, complexCollection);
|
||||
}
|
||||
|
||||
private Calendar getDateTime(final int year, final int month, final int day,
|
||||
|
@ -610,7 +605,7 @@ public class DataCreator {
|
|||
protected static void setLink(Entity entity, final String navigationPropertyName, final Entity target) {
|
||||
Link link = entity.getNavigationLink(navigationPropertyName);
|
||||
if (link == null) {
|
||||
link = new LinkImpl();
|
||||
link = new Link();
|
||||
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
|
||||
link.setTitle(navigationPropertyName);
|
||||
entity.getNavigationLinks().add(link);
|
||||
|
@ -621,10 +616,10 @@ public class DataCreator {
|
|||
protected static void setLinks(Entity entity, final String navigationPropertyName, final Entity... targets) {
|
||||
Link link = entity.getNavigationLink(navigationPropertyName);
|
||||
if (link == null) {
|
||||
link = new LinkImpl();
|
||||
link = new Link();
|
||||
link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
|
||||
link.setTitle(navigationPropertyName);
|
||||
EntitySet target = new EntitySetImpl();
|
||||
EntitySet target = new EntitySet();
|
||||
target.getEntities().addAll(Arrays.asList(targets));
|
||||
link.setInlineEntitySet(target);
|
||||
entity.getNavigationLinks().add(link);
|
||||
|
|
|
@ -40,17 +40,12 @@ import org.apache.olingo.commons.api.edm.EdmFunction;
|
|||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt16;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
|
@ -137,7 +132,7 @@ public class DataProvider {
|
|||
final EntitySet entitySet = readAll(edmEntitySet);
|
||||
final List<Entity> entities = entitySet.getEntities();
|
||||
final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntitySet.getEntityType());
|
||||
final Entity newEntity = new EntityImpl();
|
||||
final Entity newEntity = new Entity();
|
||||
newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
|
||||
for (final String keyName : edmEntityType.getKeyPredicateNames()) {
|
||||
newEntity.addProperty(DataCreator.createPrimitive(keyName, newKey.get(keyName)));
|
||||
|
@ -154,17 +149,19 @@ public class DataProvider {
|
|||
// Weak key construction
|
||||
final HashMap<String, Object> keys = new HashMap<String, Object>();
|
||||
for (final String keyName : entityType.getKeyPredicateNames()) {
|
||||
final EdmType type = entityType.getProperty(keyName).getType();
|
||||
final FullQualifiedName typeName = entityType.getProperty(keyName).getType().getFullQualifiedName();
|
||||
Object newValue = null;
|
||||
|
||||
if (type instanceof EdmInt16 || type instanceof EdmInt32 || type instanceof EdmInt64) {
|
||||
if (EdmPrimitiveTypeKind.Int16.getFullQualifiedName().equals(typeName)
|
||||
|| EdmPrimitiveTypeKind.Int32.getFullQualifiedName().equals(typeName)
|
||||
|| EdmPrimitiveTypeKind.Int64.getFullQualifiedName().equals(typeName)) {
|
||||
// Integer keys
|
||||
newValue = Integer.valueOf(1);
|
||||
|
||||
while (!isFree(newValue, keyName, entities)) {
|
||||
newValue = ((Integer) newValue) + 1;
|
||||
}
|
||||
} else if (type instanceof EdmString) {
|
||||
} else if (EdmPrimitiveTypeKind.String.getFullQualifiedName().equals(typeName)) {
|
||||
// String keys
|
||||
newValue = String.valueOf(1);
|
||||
int i = 0;
|
||||
|
@ -431,7 +428,7 @@ public class DataProvider {
|
|||
|
||||
private ComplexValue createComplexValue(final EdmProperty edmProperty, final ComplexValue complexValue,
|
||||
final boolean patch) throws DataProviderException {
|
||||
final ComplexValueImpl result = new ComplexValueImpl();
|
||||
final ComplexValue result = new ComplexValue();
|
||||
final EdmComplexType edmType = (EdmComplexType) edmProperty.getType();
|
||||
final List<Property> givenProperties = complexValue.getValue();
|
||||
|
||||
|
@ -446,7 +443,7 @@ public class DataProvider {
|
|||
updateProperty(innerEdmProperty, newProperty, currentProperty, patch);
|
||||
} else {
|
||||
if (innerEdmProperty.isNullable()) {
|
||||
// Check complex properties ... maybe null is not allowed
|
||||
// Check complex properties ... may be null is not allowed
|
||||
if (edmProperty.getType().getKind() == EdmTypeKind.COMPLEX) {
|
||||
updateProperty(innerEdmProperty, newProperty, null, patch);
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
@ -27,8 +27,7 @@ import org.apache.olingo.commons.api.data.EntitySet;
|
|||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.uri.UriParameter;
|
||||
import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException;
|
||||
|
||||
|
@ -38,7 +37,7 @@ public class FunctionData {
|
|||
final Map<String, EntitySet> data) throws DataProviderException {
|
||||
if (name.equals("UFCRTCollETTwoKeyNavParam")) {
|
||||
final List<Entity> esTwoKeyNav = data.get("ESTwoKeyNav").getEntities();
|
||||
EntitySet result = new EntitySetImpl();
|
||||
EntitySet result = new EntitySet();
|
||||
final int endIndex = parameters.isEmpty() ? 0 : Short.valueOf(parameters.get(0).getText());
|
||||
result.getEntities().addAll(
|
||||
esTwoKeyNav.subList(0,
|
||||
|
@ -85,15 +84,16 @@ public class FunctionData {
|
|||
DataCreator.createPrimitive("PropertyString", "UFCRTCTTwoPrim string value"));
|
||||
} else if (name.equals("UFCRTCTTwoPrimParam")) {
|
||||
try {
|
||||
|
||||
OData oData = OData.newInstance();
|
||||
return DataCreator.createComplex(name,
|
||||
DataCreator.createPrimitive("PropertyInt16",
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16).valueOfString(
|
||||
getParameterText("ParameterInt16", parameters),
|
||||
DataCreator.createPrimitive("PropertyInt16", oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16)
|
||||
.valueOfString(getParameterText("ParameterInt16", parameters),
|
||||
null, null, null, null, null, Short.class)),
|
||||
DataCreator.createPrimitive("PropertyString",
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String).valueOfString(
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String).fromUriLiteral(
|
||||
getParameterText("ParameterString", parameters)),
|
||||
DataCreator.createPrimitive("PropertyString", oData
|
||||
.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String)
|
||||
.valueOfString(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String)
|
||||
.fromUriLiteral(getParameterText("ParameterString", parameters)),
|
||||
null, null, null, null, null, String.class)));
|
||||
} catch (final EdmPrimitiveTypeException e) {
|
||||
throw new DataProviderException("Error in function " + name + ".", e);
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.apache.olingo.commons.api.http.HttpContentType;
|
|||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
|
@ -77,11 +76,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
|||
EntityProcessor, ActionEntityProcessor, MediaEntityProcessor,
|
||||
ActionVoidProcessor {
|
||||
|
||||
private final ServiceMetadata serviceMetadata;
|
||||
|
||||
public TechnicalEntityProcessor(final DataProvider dataProvider, ServiceMetadata serviceMetadata) {
|
||||
super(dataProvider);
|
||||
this.serviceMetadata = serviceMetadata;
|
||||
super(dataProvider, serviceMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,7 +97,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
|||
} else {
|
||||
// Modifying the original entitySet means modifying the "database", so we have to make a shallow
|
||||
// copy of the entity set (new EntitySet, but exactly the same data)
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
entitySet.getEntities().addAll(entitySetInitial.getEntities());
|
||||
|
||||
// Apply system query options
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
@ -40,7 +40,6 @@ import org.apache.olingo.commons.api.format.ContentType;
|
|||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
|
@ -82,12 +81,9 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
|||
ComplexProcessor, ActionComplexProcessor,
|
||||
ComplexCollectionProcessor, ActionComplexCollectionProcessor {
|
||||
|
||||
private final ServiceMetadata serviceMetadata;
|
||||
|
||||
public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider,
|
||||
ServiceMetadata serviceMetadata) {
|
||||
super(dataProvider);
|
||||
this.serviceMetadata = serviceMetadata;
|
||||
super(dataProvider, serviceMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -251,7 +247,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
|||
.build()).getContent());
|
||||
break;
|
||||
case COMPLEX:
|
||||
response.setContent(serializer.complex(this.serviceMetadata,(EdmComplexType) type, property,
|
||||
response.setContent(serializer.complex(this.serviceMetadata, (EdmComplexType) type, property,
|
||||
ComplexSerializerOptions.with().contextURL(contextURL)
|
||||
.expand(expand).select(select)
|
||||
.build()).getContent());
|
||||
|
@ -388,7 +384,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
|||
final EdmReturnType returnType = resourceParts.get(0) instanceof UriResourceFunction ?
|
||||
((UriResourceFunction) resourceParts.get(0)).getFunction().getReturnType() : null;
|
||||
final FixedFormatSerializer serializer = odata.createFixedFormatSerializer();
|
||||
response.setContent(type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
|
||||
response.setContent(type == odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Binary) ?
|
||||
serializer.binary((byte[]) property.getValue()) :
|
||||
serializer.primitiveValue(type, property.getValue(),
|
||||
PrimitiveValueSerializerOptions.with()
|
||||
|
|
|
@ -54,6 +54,11 @@ public abstract class TechnicalProcessor implements Processor {
|
|||
protected TechnicalProcessor(final DataProvider dataProvider) {
|
||||
this.dataProvider = dataProvider;
|
||||
}
|
||||
|
||||
protected TechnicalProcessor(final DataProvider dataProvider, ServiceMetadata serviceMetadata) {
|
||||
this.dataProvider = dataProvider;
|
||||
this.serviceMetadata = serviceMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final OData odata, final ServiceMetadata serviceMetadata) {
|
||||
|
|
|
@ -31,9 +31,6 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.uri.UriResource;
|
||||
import org.apache.olingo.server.api.uri.UriResourceNavigation;
|
||||
|
@ -132,9 +129,7 @@ public class ExpandSystemQueryOptionHandler {
|
|||
|
||||
public Entity transformEntityGraphToTree(final Entity entity, EdmBindingTarget edmEntitySet,
|
||||
final ExpandOption expand) throws ODataApplicationException {
|
||||
|
||||
final Entity newEntity = newEntity(entity);
|
||||
|
||||
if (hasExpandItems(expand)) {
|
||||
final boolean expandAll = expandAll(expand);
|
||||
final Set<String> expanded = expandAll ? null : getExpandedPropertyNames(expand.getExpandItems());
|
||||
|
@ -167,7 +162,7 @@ public class ExpandSystemQueryOptionHandler {
|
|||
}
|
||||
|
||||
public EntitySet newEntitySet(final EntitySet entitySet) {
|
||||
final EntitySet newEntitySet = new EntitySetImpl();
|
||||
final EntitySet newEntitySet = new EntitySet();
|
||||
newEntitySet.setCount(entitySet.getCount());
|
||||
newEntitySet.setDeltaLink(entitySet.getDeltaLink());
|
||||
newEntitySet.setNext(entitySet.getNext());
|
||||
|
@ -176,7 +171,7 @@ public class ExpandSystemQueryOptionHandler {
|
|||
}
|
||||
|
||||
private Entity newEntity(final Entity entity) {
|
||||
final Entity newEntity = new EntityImpl();
|
||||
final Entity newEntity = new Entity();
|
||||
|
||||
newEntity.getProperties().addAll(entity.getProperties());
|
||||
newEntity.getAnnotations().addAll(entity.getAnnotations());
|
||||
|
@ -195,7 +190,7 @@ public class ExpandSystemQueryOptionHandler {
|
|||
}
|
||||
|
||||
private Link newLink(Link link) {
|
||||
final Link newLink = new LinkImpl();
|
||||
final Link newLink = new Link();
|
||||
newLink.setMediaETag(link.getMediaETag());
|
||||
newLink.setTitle(link.getTitle());
|
||||
newLink.setType(link.getType());
|
||||
|
|
|
@ -26,14 +26,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
|||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmByte;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt16;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSByte;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSingle;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.primitive.EdmNull;
|
||||
|
||||
|
@ -73,13 +65,11 @@ public class TypedOperand extends VisitorOperand {
|
|||
Object newValue = null;
|
||||
for (EdmPrimitiveType asType : asTypes) {
|
||||
// Use BigDecimal for unlimited precision
|
||||
if (asType.equals(EdmDouble.getInstance())
|
||||
|| asType.equals(EdmSingle.getInstance())
|
||||
|| asType.equals(EdmDecimal.getInstance())) {
|
||||
|
||||
if (asType.equals(primDouble) || asType.equals(primSingle) || asType.equals(primDecimal)) {
|
||||
|
||||
try {
|
||||
newValue = new BigDecimal(value.toString());
|
||||
} catch(NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
// Nothing to do
|
||||
}
|
||||
} else {
|
||||
|
@ -117,18 +107,18 @@ public class TypedOperand extends VisitorOperand {
|
|||
return this;
|
||||
}
|
||||
|
||||
if (type.equals(EdmDouble.getInstance()) || oType.equals(EdmDouble.getInstance())) {
|
||||
return asTypedOperand(EdmDouble.getInstance());
|
||||
} else if (type.equals(EdmSingle.getInstance()) || oType.equals(EdmSingle.getInstance())) {
|
||||
return asTypedOperand(EdmSingle.getInstance());
|
||||
} else if (type.equals(EdmDecimal.getInstance()) || oType.equals(EdmDecimal.getInstance())) {
|
||||
return asTypedOperand(EdmDecimal.getInstance());
|
||||
} else if (type.equals(EdmInt64.getInstance()) || oType.equals(EdmInt64.getInstance())) {
|
||||
return asTypedOperand(EdmInt64.getInstance());
|
||||
} else if (type.equals(EdmInt32.getInstance()) || oType.equals(EdmInt32.getInstance())) {
|
||||
return asTypedOperand(EdmInt32.getInstance());
|
||||
} else if (type.equals(EdmInt16.getInstance()) || oType.equals(EdmInt16.getInstance())) {
|
||||
return asTypedOperand(EdmInt16.getInstance());
|
||||
if (type.equals(primDouble) || oType.equals(primDouble)) {
|
||||
return asTypedOperand(primDouble);
|
||||
} else if (type.equals(primSingle) || oType.equals(primSingle)) {
|
||||
return asTypedOperand(primSingle);
|
||||
} else if (type.equals(primDecimal) || oType.equals(primDecimal)) {
|
||||
return asTypedOperand(primDecimal);
|
||||
} else if (type.equals(primInt64) || oType.equals(primInt64)) {
|
||||
return asTypedOperand(primInt64);
|
||||
} else if (type.equals(primInt32) || oType.equals(primInt32)) {
|
||||
return asTypedOperand(primInt32);
|
||||
} else if (type.equals(primInt16) || oType.equals(primInt16)) {
|
||||
return asTypedOperand(primInt16);
|
||||
} else {
|
||||
return asTypedOperand((EdmPrimitiveType) type);
|
||||
}
|
||||
|
@ -151,17 +141,19 @@ public class TypedOperand extends VisitorOperand {
|
|||
}
|
||||
|
||||
public boolean isIntegerType() {
|
||||
return is(EdmByte.getInstance(),
|
||||
EdmSByte.getInstance(),
|
||||
EdmInt16.getInstance(),
|
||||
EdmInt32.getInstance(),
|
||||
EdmInt64.getInstance());
|
||||
return is(
|
||||
primByte,
|
||||
primSByte,
|
||||
primInt16,
|
||||
primInt32,
|
||||
primInt64);
|
||||
}
|
||||
|
||||
public boolean isDecimalType() {
|
||||
return is(EdmSingle.getInstance(),
|
||||
EdmDouble.getInstance(),
|
||||
EdmDecimal.getInstance());
|
||||
return is(
|
||||
primSingle,
|
||||
primDouble,
|
||||
primDecimal);
|
||||
}
|
||||
|
||||
public boolean is(EdmPrimitiveType... types) {
|
||||
|
|
|
@ -23,20 +23,6 @@ import java.util.Locale;
|
|||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmBoolean;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmByte;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt16;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSByte;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSingle;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmTimeOfDay;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.primitive.EdmNull;
|
||||
|
||||
|
@ -84,65 +70,65 @@ public class UntypedOperand extends VisitorOperand {
|
|||
}
|
||||
|
||||
// String
|
||||
if ((newValue = tryCast(literal, EdmString.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmString.getInstance());
|
||||
if ((newValue = tryCast(literal, primString)) != null) {
|
||||
return new TypedOperand(newValue, primString);
|
||||
}
|
||||
|
||||
// Boolean
|
||||
if ((newValue = tryCast(literal, EdmBoolean.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmBoolean.getInstance());
|
||||
if ((newValue = tryCast(literal, primBoolean)) != null) {
|
||||
return new TypedOperand(newValue, primBoolean);
|
||||
}
|
||||
|
||||
// Date
|
||||
if ((newValue = tryCast(literal, EdmDateTimeOffset.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmDateTimeOffset.getInstance());
|
||||
if ((newValue = tryCast(literal, primDateTimeOffset)) != null) {
|
||||
return new TypedOperand(newValue, primDateTimeOffset);
|
||||
}
|
||||
|
||||
if ((newValue = tryCast(literal, EdmDate.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmDate.getInstance());
|
||||
if ((newValue = tryCast(literal, primDate)) != null) {
|
||||
return new TypedOperand(newValue, primDate);
|
||||
}
|
||||
|
||||
if ((newValue = tryCast(literal, EdmTimeOfDay.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmTimeOfDay.getInstance());
|
||||
if ((newValue = tryCast(literal, primTimeOfDay)) != null) {
|
||||
return new TypedOperand(newValue, primTimeOfDay);
|
||||
}
|
||||
|
||||
if ((newValue = tryCast(literal, EdmDuration.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmDuration.getInstance());
|
||||
if ((newValue = tryCast(literal, primDuration)) != null) {
|
||||
return new TypedOperand(newValue, primDuration);
|
||||
}
|
||||
|
||||
// Integer
|
||||
if ((newValue = tryCast(literal, EdmSByte.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmSByte.getInstance());
|
||||
if ((newValue = tryCast(literal, primSByte)) != null) {
|
||||
return new TypedOperand(newValue, primSByte);
|
||||
}
|
||||
|
||||
if ((newValue = tryCast(literal, EdmByte.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmByte.getInstance());
|
||||
if ((newValue = tryCast(literal, primByte)) != null) {
|
||||
return new TypedOperand(newValue, primByte);
|
||||
}
|
||||
|
||||
if ((newValue = tryCast(literal, EdmInt16.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmInt16.getInstance());
|
||||
if ((newValue = tryCast(literal, primInt16)) != null) {
|
||||
return new TypedOperand(newValue, primInt16);
|
||||
}
|
||||
|
||||
if ((newValue = tryCast(literal, EdmInt32.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmInt32.getInstance());
|
||||
if ((newValue = tryCast(literal, primInt32)) != null) {
|
||||
return new TypedOperand(newValue, primInt32);
|
||||
}
|
||||
|
||||
if ((newValue = tryCast(literal, EdmInt64.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmInt64.getInstance());
|
||||
if ((newValue = tryCast(literal, primInt64)) != null) {
|
||||
return new TypedOperand(newValue, primInt64);
|
||||
}
|
||||
|
||||
// Decimal
|
||||
if ((newValue = tryCast(literal, EdmDecimal.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmDecimal.getInstance());
|
||||
if ((newValue = tryCast(literal, primDecimal)) != null) {
|
||||
return new TypedOperand(newValue, primDecimal);
|
||||
}
|
||||
|
||||
// Float
|
||||
if ((newValue = tryCast(literal, EdmSingle.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmSingle.getInstance());
|
||||
if ((newValue = tryCast(literal, primSingle)) != null) {
|
||||
return new TypedOperand(newValue, primSingle);
|
||||
}
|
||||
|
||||
if ((newValue = tryCast(literal, EdmDouble.getInstance())) != null) {
|
||||
return new TypedOperand(newValue, EdmDouble.getInstance());
|
||||
if ((newValue = tryCast(literal, primDouble)) != null) {
|
||||
return new TypedOperand(newValue, primDouble);
|
||||
}
|
||||
|
||||
throw new ODataApplicationException("Could not determine type for literal " + literal,
|
||||
|
|
|
@ -24,32 +24,57 @@ import java.util.HashMap;
|
|||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmByte;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt16;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSByte;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSingle;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
|
||||
public abstract class VisitorOperand {
|
||||
final static private HashMap<EdmType, Class<?>> defaultTypeMapping = new HashMap<EdmType, Class<?>>();
|
||||
protected Object value;
|
||||
protected static final OData oData;
|
||||
protected static final EdmPrimitiveType primString;
|
||||
protected static final EdmPrimitiveType primBoolean;
|
||||
protected static final EdmPrimitiveType primDateTimeOffset;
|
||||
protected static final EdmPrimitiveType primDate;
|
||||
protected static final EdmPrimitiveType primTimeOfDay;
|
||||
protected static final EdmPrimitiveType primDuration;
|
||||
protected static final EdmPrimitiveType primSByte;
|
||||
protected static final EdmPrimitiveType primByte;
|
||||
protected static final EdmPrimitiveType primInt16;
|
||||
protected static final EdmPrimitiveType primInt32;
|
||||
protected static final EdmPrimitiveType primInt64;
|
||||
protected static final EdmPrimitiveType primDecimal;
|
||||
protected static final EdmPrimitiveType primSingle;
|
||||
protected static final EdmPrimitiveType primDouble;
|
||||
|
||||
static {
|
||||
defaultTypeMapping.put(EdmByte.getInstance(), BigInteger.class);
|
||||
defaultTypeMapping.put(EdmSByte.getInstance(), BigInteger.class);
|
||||
defaultTypeMapping.put(EdmInt16.getInstance(), BigInteger.class);
|
||||
defaultTypeMapping.put(EdmInt32.getInstance(), BigInteger.class);
|
||||
defaultTypeMapping.put(EdmInt64.getInstance(), BigInteger.class);
|
||||
oData = OData.newInstance();
|
||||
primString = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String);
|
||||
primBoolean = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean);
|
||||
primDateTimeOffset = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.DateTimeOffset);
|
||||
primDate = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Date);
|
||||
primTimeOfDay = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.TimeOfDay);
|
||||
primDuration = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Duration);
|
||||
primSByte = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.SByte);
|
||||
primByte = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte);
|
||||
primInt16 = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16);
|
||||
primInt32 = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32);
|
||||
primInt64 = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int64);
|
||||
primDecimal = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal);
|
||||
primSingle = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Single);
|
||||
primDouble = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double);
|
||||
|
||||
defaultTypeMapping.put(primByte, BigInteger.class);
|
||||
defaultTypeMapping.put(primSByte, BigInteger.class);
|
||||
defaultTypeMapping.put(primInt16, BigInteger.class);
|
||||
defaultTypeMapping.put(primInt32, BigInteger.class);
|
||||
defaultTypeMapping.put(primInt64, BigInteger.class);
|
||||
|
||||
defaultTypeMapping.put(EdmSingle.getInstance(), BigDecimal.class);
|
||||
defaultTypeMapping.put(EdmDouble.getInstance(), BigDecimal.class);
|
||||
defaultTypeMapping.put(EdmDecimal.getInstance(), BigDecimal.class);
|
||||
defaultTypeMapping.put(primSingle, BigDecimal.class);
|
||||
defaultTypeMapping.put(primDouble, BigDecimal.class);
|
||||
defaultTypeMapping.put(primDecimal, BigDecimal.class);
|
||||
}
|
||||
|
||||
public VisitorOperand(Object value) {
|
||||
|
|
|
@ -24,19 +24,11 @@ import java.sql.Timestamp;
|
|||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmBoolean;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmByte;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt16;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSByte;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSingle;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.TypedOperand;
|
||||
|
@ -62,6 +54,40 @@ public class BinaryOperator {
|
|||
private static final int EQUALS = 0;
|
||||
private static final int LESS_THAN = -1;
|
||||
private static final int GREATER_THAN = 1;
|
||||
|
||||
protected static final OData oData;
|
||||
protected static final EdmPrimitiveType primString;
|
||||
protected static final EdmPrimitiveType primBoolean;
|
||||
protected static final EdmPrimitiveType primDateTimeOffset;
|
||||
protected static final EdmPrimitiveType primDate;
|
||||
protected static final EdmPrimitiveType primTimeOfDay;
|
||||
protected static final EdmPrimitiveType primDuration;
|
||||
protected static final EdmPrimitiveType primSByte;
|
||||
protected static final EdmPrimitiveType primByte;
|
||||
protected static final EdmPrimitiveType primInt16;
|
||||
protected static final EdmPrimitiveType primInt32;
|
||||
protected static final EdmPrimitiveType primInt64;
|
||||
protected static final EdmPrimitiveType primDecimal;
|
||||
protected static final EdmPrimitiveType primSingle;
|
||||
protected static final EdmPrimitiveType primDouble;
|
||||
|
||||
static {
|
||||
oData = OData.newInstance();
|
||||
primString = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String);
|
||||
primBoolean = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean);
|
||||
primDateTimeOffset = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.DateTimeOffset);
|
||||
primDate = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Date);
|
||||
primTimeOfDay = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.TimeOfDay);
|
||||
primDuration = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Duration);
|
||||
primSByte = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.SByte);
|
||||
primByte = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte);
|
||||
primInt16 = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16);
|
||||
primInt32 = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32);
|
||||
primInt64 = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int64);
|
||||
primDecimal = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal);
|
||||
primSingle = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Single);
|
||||
primDouble = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double);
|
||||
}
|
||||
|
||||
private TypedOperand right;
|
||||
private TypedOperand left;
|
||||
|
@ -77,14 +103,14 @@ public class BinaryOperator {
|
|||
|
||||
public VisitorOperand andOperator() throws ODataApplicationException {
|
||||
Boolean result = null;
|
||||
if (left.is(EdmBoolean.getInstance()) && right.is(EdmBoolean.getInstance())) {
|
||||
if (left.is(primBoolean) && right.is(primBoolean)) {
|
||||
if (Boolean.TRUE.equals(left.getValue()) && Boolean.TRUE.equals(right.getValue())) {
|
||||
result = true;
|
||||
} else if (Boolean.FALSE.equals(left.getValue()) || Boolean.FALSE.equals(right.getValue())) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return new TypedOperand(result, EdmBoolean.getInstance());
|
||||
return new TypedOperand(result, primBoolean);
|
||||
} else {
|
||||
throw new ODataApplicationException("Add operator needs two binary operands",
|
||||
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
|
||||
|
@ -93,14 +119,14 @@ public class BinaryOperator {
|
|||
|
||||
public VisitorOperand orOperator() throws ODataApplicationException {
|
||||
Boolean result = null;
|
||||
if (left.is(EdmBoolean.getInstance()) && right.is(EdmBoolean.getInstance())) {
|
||||
if (left.is(primBoolean) && right.is(primBoolean)) {
|
||||
if (Boolean.TRUE.equals(left.getValue()) || Boolean.TRUE.equals(right.getValue())) {
|
||||
result = true;
|
||||
} else if (Boolean.FALSE.equals(left.getValue()) && Boolean.FALSE.equals(right.getValue())) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return new TypedOperand(result, EdmBoolean.getInstance());
|
||||
return new TypedOperand(result, primBoolean);
|
||||
} else {
|
||||
throw new ODataApplicationException("Or operator needs two binary operands",
|
||||
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
|
||||
|
@ -109,12 +135,12 @@ public class BinaryOperator {
|
|||
|
||||
public VisitorOperand equalsOperator() {
|
||||
final boolean result = isBinaryComparisonNecessary() && binaryComparison(EQUALS);
|
||||
return new TypedOperand(result, EdmBoolean.getInstance());
|
||||
return new TypedOperand(result, primBoolean);
|
||||
}
|
||||
|
||||
public VisitorOperand notEqualsOperator() {
|
||||
final VisitorOperand equalsOperator = equalsOperator();
|
||||
return new TypedOperand(!(Boolean) equalsOperator.getValue(), EdmBoolean.getInstance());
|
||||
return new TypedOperand(!(Boolean) equalsOperator.getValue(), primBoolean);
|
||||
}
|
||||
|
||||
private boolean isBinaryComparisonNecessary() {
|
||||
|
@ -124,22 +150,22 @@ public class BinaryOperator {
|
|||
|
||||
public VisitorOperand greaterEqualsOperator() {
|
||||
final boolean result = isBinaryComparisonNecessary() && binaryComparison(GREATER_THAN, EQUALS);
|
||||
return new TypedOperand(result, EdmBoolean.getInstance());
|
||||
return new TypedOperand(result, primBoolean);
|
||||
}
|
||||
|
||||
public VisitorOperand greaterThanOperator() {
|
||||
final boolean result = isBinaryComparisonNecessary() && binaryComparison(GREATER_THAN);
|
||||
return new TypedOperand(result, EdmBoolean.getInstance());
|
||||
return new TypedOperand(result, primBoolean);
|
||||
}
|
||||
|
||||
public VisitorOperand lessEqualsOperator() {
|
||||
final boolean result = isBinaryComparisonNecessary() && binaryComparison(LESS_THAN, EQUALS);
|
||||
return new TypedOperand(result, EdmBoolean.getInstance());
|
||||
return new TypedOperand(result, primBoolean);
|
||||
}
|
||||
|
||||
public VisitorOperand lessThanOperator() {
|
||||
final boolean result = isBinaryComparisonNecessary() && binaryComparison(LESS_THAN);
|
||||
return new TypedOperand(result, EdmBoolean.getInstance());
|
||||
return new TypedOperand(result, primBoolean);
|
||||
}
|
||||
|
||||
private boolean binaryComparison(int... expect) {
|
||||
|
@ -176,7 +202,7 @@ public class BinaryOperator {
|
|||
} else if (left.isDecimalType()) {
|
||||
final BigDecimal result = decimalArithmeticOperation(operator);
|
||||
return new TypedOperand(result, determineResultType(result, left));
|
||||
} else if (left.is(EdmDate.getInstance(), EdmDuration.getInstance(), EdmDateTimeOffset.getInstance())) {
|
||||
} else if (left.is(primDate, primDuration, primDateTimeOffset)) {
|
||||
return dateArithmeticOperation(operator);
|
||||
} else {
|
||||
throw new ODataApplicationException("Invalid type", HttpStatusCode.BAD_REQUEST.getStatusCode(),
|
||||
|
@ -190,81 +216,81 @@ public class BinaryOperator {
|
|||
if (leftOperand.isDecimalType()) {
|
||||
final BigDecimal value = (BigDecimal) arithmeticResult;
|
||||
if (value.compareTo(EDM_SINGLE_MIN) >= 0 && value.compareTo(EDM_SINGLE_MAX) <= 0) {
|
||||
return EdmSingle.getInstance();
|
||||
return primSingle;
|
||||
} else {
|
||||
return EdmDouble.getInstance();
|
||||
return primDouble;
|
||||
}
|
||||
} else {
|
||||
final BigInteger value = (BigInteger) arithmeticResult;
|
||||
|
||||
if (value.compareTo(EDN_SBYTE_MAX) <= 0 && value.compareTo(EDM_SBYTE_MIN) >= 0) {
|
||||
return EdmSByte.getInstance();
|
||||
return primSByte;
|
||||
}
|
||||
if (value.compareTo(EDM_BYTE_MAX) <= 0 && value.compareTo(EDM_BYTE_MIN) >= 0) {
|
||||
return EdmByte.getInstance();
|
||||
return primByte;
|
||||
}
|
||||
if (value.compareTo(EDM_INT16_MAX) <= 0 && value.compareTo(EDM_INT16_MIN) >= 0) {
|
||||
return EdmInt16.getInstance();
|
||||
return primInt16;
|
||||
}
|
||||
if (value.compareTo(EDM_INT32_MAX) <= 0 && value.compareTo(EDM_INT32_MIN) >= 0) {
|
||||
return EdmInt32.getInstance();
|
||||
return primInt32;
|
||||
}
|
||||
if (value.compareTo(EDM_INT64_MAX) <= 0 && value.compareTo(EDM_INT64_MIN) >= 0) {
|
||||
return EdmInt64.getInstance();
|
||||
return primInt64;
|
||||
}
|
||||
// Choose double instead single because precision is higher (52 bits instead of 23)
|
||||
return EdmDouble.getInstance();
|
||||
return primDouble;
|
||||
}
|
||||
}
|
||||
|
||||
private VisitorOperand dateArithmeticOperation(BinaryOperatorKind operator) throws ODataApplicationException {
|
||||
VisitorOperand result = null;
|
||||
|
||||
if (left.is(EdmDate.getInstance())) {
|
||||
if (right.is(EdmDate.getInstance()) && operator == BinaryOperatorKind.SUB) {
|
||||
if (left.is(primDate)) {
|
||||
if (right.is(primDate) && operator == BinaryOperatorKind.SUB) {
|
||||
long millis = left.getTypedValue(Calendar.class).getTimeInMillis()
|
||||
- left.getTypedValue(Calendar.class).getTimeInMillis();
|
||||
|
||||
result = new TypedOperand(new BigDecimal(millis).divide(FACTOR_SECOND), EdmDuration.getInstance());
|
||||
} else if (right.is(EdmDuration.getInstance()) && operator == BinaryOperatorKind.ADD) {
|
||||
result = new TypedOperand(new BigDecimal(millis).divide(FACTOR_SECOND), primDuration);
|
||||
} else if (right.is(primDuration) && operator == BinaryOperatorKind.ADD) {
|
||||
long millis = left.getTypedValue(Calendar.class).getTimeInMillis()
|
||||
+ (right.getTypedValue(BigDecimal.class).longValue() * FACTOR_SECOND_INT);
|
||||
|
||||
result = new TypedOperand(new Timestamp(millis), EdmDateTimeOffset.getInstance());
|
||||
} else if (right.is(EdmDuration.getInstance()) && operator == BinaryOperatorKind.SUB) {
|
||||
result = new TypedOperand(new Timestamp(millis), primDateTimeOffset);
|
||||
} else if (right.is(primDuration) && operator == BinaryOperatorKind.SUB) {
|
||||
long millis = left.getTypedValue(Calendar.class).getTimeInMillis()
|
||||
- (right.getTypedValue(BigDecimal.class).longValue() * FACTOR_SECOND_INT);
|
||||
|
||||
result = new TypedOperand(new Timestamp(millis), EdmDateTimeOffset.getInstance());
|
||||
result = new TypedOperand(new Timestamp(millis), primDateTimeOffset);
|
||||
}
|
||||
} else if (left.is(EdmDuration.getInstance())) {
|
||||
if (right.is(EdmDuration.getInstance()) && operator == BinaryOperatorKind.ADD) {
|
||||
} else if (left.is(primDuration)) {
|
||||
if (right.is(primDuration) && operator == BinaryOperatorKind.ADD) {
|
||||
long seconds = left.getTypedValue(BigDecimal.class).longValue()
|
||||
+ right.getTypedValue(BigDecimal.class).longValue();
|
||||
|
||||
result = new TypedOperand(new BigDecimal(seconds), EdmDuration.getInstance());
|
||||
} else if (right.is(EdmDuration.getInstance()) && operator == BinaryOperatorKind.SUB) {
|
||||
result = new TypedOperand(new BigDecimal(seconds), primDuration);
|
||||
} else if (right.is(primDuration) && operator == BinaryOperatorKind.SUB) {
|
||||
long seconds = left.getTypedValue(BigDecimal.class).longValue()
|
||||
- right.getTypedValue(BigDecimal.class).longValue();
|
||||
|
||||
result = new TypedOperand(new BigDecimal(seconds), EdmDuration.getInstance());
|
||||
result = new TypedOperand(new BigDecimal(seconds), primDuration);
|
||||
}
|
||||
} else if (left.is(EdmDateTimeOffset.getInstance())) {
|
||||
if (right.is(EdmDuration.getInstance()) && operator == BinaryOperatorKind.ADD) {
|
||||
} else if (left.is(primDateTimeOffset)) {
|
||||
if (right.is(primDuration) && operator == BinaryOperatorKind.ADD) {
|
||||
long millis = left.getTypedValue(Timestamp.class).getTime()
|
||||
+ (right.getTypedValue(BigDecimal.class).longValue() * FACTOR_SECOND_INT);
|
||||
|
||||
result = new TypedOperand(new Timestamp(millis), EdmDateTimeOffset.getInstance());
|
||||
} else if (right.is(EdmDuration.getInstance()) && operator == BinaryOperatorKind.SUB) {
|
||||
result = new TypedOperand(new Timestamp(millis), primDateTimeOffset);
|
||||
} else if (right.is(primDuration) && operator == BinaryOperatorKind.SUB) {
|
||||
long millis = left.getTypedValue(Timestamp.class).getTime()
|
||||
- (right.getTypedValue(BigDecimal.class).longValue() * FACTOR_SECOND_INT);
|
||||
|
||||
result = new TypedOperand(new Timestamp(millis), EdmDateTimeOffset.getInstance());
|
||||
} else if (right.is(EdmDateTimeOffset.getInstance()) && operator == BinaryOperatorKind.SUB) {
|
||||
result = new TypedOperand(new Timestamp(millis), primDateTimeOffset);
|
||||
} else if (right.is(primDateTimeOffset) && operator == BinaryOperatorKind.SUB) {
|
||||
long millis = left.getTypedValue(Timestamp.class).getTime()
|
||||
- right.getTypedValue(Timestamp.class).getTime();
|
||||
|
||||
result = new TypedOperand(new BigDecimal(millis).divide(FACTOR_SECOND), EdmDuration.getInstance());
|
||||
result = new TypedOperand(new BigDecimal(millis).divide(FACTOR_SECOND), primDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,21 +30,50 @@ import java.util.Locale;
|
|||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmBoolean;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmTimeOfDay;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.TypedOperand;
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.VisitorOperand;
|
||||
|
||||
public class MethodCallOperator {
|
||||
|
||||
protected static final OData oData;
|
||||
protected static final EdmPrimitiveType primString;
|
||||
protected static final EdmPrimitiveType primBoolean;
|
||||
protected static final EdmPrimitiveType primDateTimeOffset;
|
||||
protected static final EdmPrimitiveType primDate;
|
||||
protected static final EdmPrimitiveType primTimeOfDay;
|
||||
protected static final EdmPrimitiveType primDuration;
|
||||
protected static final EdmPrimitiveType primSByte;
|
||||
protected static final EdmPrimitiveType primByte;
|
||||
protected static final EdmPrimitiveType primInt16;
|
||||
protected static final EdmPrimitiveType primInt32;
|
||||
protected static final EdmPrimitiveType primInt64;
|
||||
protected static final EdmPrimitiveType primDecimal;
|
||||
protected static final EdmPrimitiveType primSingle;
|
||||
protected static final EdmPrimitiveType primDouble;
|
||||
|
||||
static {
|
||||
oData = OData.newInstance();
|
||||
primString = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String);
|
||||
primBoolean = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean);
|
||||
primDateTimeOffset = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.DateTimeOffset);
|
||||
primDate = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Date);
|
||||
primTimeOfDay = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.TimeOfDay);
|
||||
primDuration = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Duration);
|
||||
primSByte = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.SByte);
|
||||
primByte = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte);
|
||||
primInt16 = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16);
|
||||
primInt32 = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32);
|
||||
primInt64 = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int64);
|
||||
primDecimal = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal);
|
||||
primSingle = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Single);
|
||||
primDouble = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double);
|
||||
}
|
||||
|
||||
final private List<VisitorOperand> parameters;
|
||||
|
||||
public MethodCallOperator(List<VisitorOperand> parameters) {
|
||||
|
@ -57,7 +86,7 @@ public class MethodCallOperator {
|
|||
public Object perform(List<String> params) {
|
||||
return params.get(0).endsWith(params.get(1));
|
||||
}
|
||||
}, EdmBoolean.getInstance());
|
||||
}, primBoolean);
|
||||
}
|
||||
|
||||
public VisitorOperand indexOf() throws ODataApplicationException {
|
||||
|
@ -67,7 +96,7 @@ public class MethodCallOperator {
|
|||
// If the first string do not contain the second string, return -1. See OASIS JIRA ODATA-780
|
||||
return params.get(0).indexOf(params.get(1));
|
||||
}
|
||||
}, EdmInt32.getInstance());
|
||||
}, primInt32);
|
||||
}
|
||||
|
||||
public VisitorOperand startsWith() throws ODataApplicationException {
|
||||
|
@ -76,7 +105,7 @@ public class MethodCallOperator {
|
|||
public Object perform(List<String> params) {
|
||||
return params.get(0).startsWith(params.get(1));
|
||||
}
|
||||
}, EdmBoolean.getInstance());
|
||||
}, primBoolean);
|
||||
}
|
||||
|
||||
public VisitorOperand toLower() throws ODataApplicationException {
|
||||
|
@ -85,7 +114,7 @@ public class MethodCallOperator {
|
|||
public Object perform(List<String> params) {
|
||||
return params.get(0).toLowerCase();
|
||||
}
|
||||
}, EdmString.getInstance());
|
||||
}, primString);
|
||||
}
|
||||
|
||||
public VisitorOperand toUpper() throws ODataApplicationException {
|
||||
|
@ -94,7 +123,7 @@ public class MethodCallOperator {
|
|||
public Object perform(List<String> params) {
|
||||
return params.get(0).toUpperCase();
|
||||
}
|
||||
}, EdmString.getInstance());
|
||||
}, primString);
|
||||
}
|
||||
|
||||
public VisitorOperand trim() throws ODataApplicationException {
|
||||
|
@ -103,7 +132,7 @@ public class MethodCallOperator {
|
|||
public Object perform(List<String> params) {
|
||||
return params.get(0).trim();
|
||||
}
|
||||
}, EdmString.getInstance());
|
||||
}, primString);
|
||||
}
|
||||
|
||||
public VisitorOperand substring() throws ODataApplicationException {
|
||||
|
@ -113,8 +142,8 @@ public class MethodCallOperator {
|
|||
final TypedOperand startOperand = parameters.get(1).asTypedOperand();
|
||||
|
||||
if (valueOperand.isNull() || startOperand.isNull()) {
|
||||
return new TypedOperand(null, EdmString.getInstance());
|
||||
} else if (valueOperand.is(EdmString.getInstance()) && startOperand.isIntegerType()) {
|
||||
return new TypedOperand(null, primString);
|
||||
} else if (valueOperand.is(primString) && startOperand.isIntegerType()) {
|
||||
final String value = valueOperand.getTypedValue(String.class);
|
||||
int start = Math.min(startOperand.getTypedValue(BigInteger.class).intValue(), value.length());
|
||||
start = start < 0 ? 0 : start;
|
||||
|
@ -125,7 +154,7 @@ public class MethodCallOperator {
|
|||
final TypedOperand lengthOperand = parameters.get(2).asTypedOperand();
|
||||
|
||||
if (lengthOperand.isNull()) {
|
||||
return new TypedOperand(null, EdmString.getInstance());
|
||||
return new TypedOperand(null, primString);
|
||||
} else if (lengthOperand.isIntegerType()) {
|
||||
end = Math.min(start + lengthOperand.getTypedValue(BigInteger.class).intValue(), value.length());
|
||||
end = end < 0 ? 0 : end;
|
||||
|
@ -136,7 +165,7 @@ public class MethodCallOperator {
|
|||
}
|
||||
|
||||
return new TypedOperand(value.substring(start, end),
|
||||
EdmString.getInstance());
|
||||
primString);
|
||||
} else {
|
||||
throw new ODataApplicationException("Substring has invalid parameters. First parameter should be Edm.String,"
|
||||
+ " second parameter should be Edm.Int32", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
|
||||
|
@ -149,7 +178,7 @@ public class MethodCallOperator {
|
|||
public Object perform(List<String> params) {
|
||||
return params.get(0).contains(params.get(1));
|
||||
}
|
||||
}, EdmBoolean.getInstance());
|
||||
}, primBoolean);
|
||||
}
|
||||
|
||||
public VisitorOperand concat() throws ODataApplicationException {
|
||||
|
@ -158,7 +187,7 @@ public class MethodCallOperator {
|
|||
public Object perform(List<String> params) {
|
||||
return params.get(0) + params.get(1);
|
||||
}
|
||||
}, EdmString.getInstance());
|
||||
}, primString);
|
||||
}
|
||||
|
||||
public VisitorOperand length() throws ODataApplicationException {
|
||||
|
@ -167,7 +196,7 @@ public class MethodCallOperator {
|
|||
public Object perform(List<String> params) {
|
||||
return params.get(0).length();
|
||||
}
|
||||
}, EdmInt32.getInstance());
|
||||
}, primInt32);
|
||||
}
|
||||
|
||||
public VisitorOperand year() throws ODataApplicationException {
|
||||
|
@ -176,7 +205,7 @@ public class MethodCallOperator {
|
|||
public Object perform(Calendar calendar, TypedOperand operand) {
|
||||
return calendar.get(Calendar.YEAR);
|
||||
}
|
||||
}, EdmInt32.getInstance(), EdmDateTimeOffset.getInstance(), EdmDate.getInstance());
|
||||
}, primInt32, primDateTimeOffset, primDate);
|
||||
}
|
||||
|
||||
public VisitorOperand month() throws ODataApplicationException {
|
||||
|
@ -186,7 +215,7 @@ public class MethodCallOperator {
|
|||
// Month is 0-based!
|
||||
return calendar.get(Calendar.MONTH) + 1;
|
||||
}
|
||||
}, EdmInt32.getInstance(), EdmDateTimeOffset.getInstance(), EdmDate.getInstance());
|
||||
}, primInt32, primDateTimeOffset, primDate);
|
||||
}
|
||||
|
||||
public VisitorOperand day() throws ODataApplicationException {
|
||||
|
@ -195,7 +224,7 @@ public class MethodCallOperator {
|
|||
public Object perform(Calendar calendar, TypedOperand operand) {
|
||||
return calendar.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
}, EdmInt32.getInstance(), EdmDateTimeOffset.getInstance(), EdmDate.getInstance());
|
||||
}, primInt32, primDateTimeOffset, primDate);
|
||||
}
|
||||
|
||||
public VisitorOperand hour() throws ODataApplicationException {
|
||||
|
@ -204,7 +233,7 @@ public class MethodCallOperator {
|
|||
public Object perform(Calendar calendar, TypedOperand operand) {
|
||||
return calendar.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
}, EdmInt32.getInstance(), EdmDateTimeOffset.getInstance(), EdmTimeOfDay.getInstance());
|
||||
}, primInt32, primDateTimeOffset, primTimeOfDay);
|
||||
}
|
||||
|
||||
public VisitorOperand minute() throws ODataApplicationException {
|
||||
|
@ -213,7 +242,7 @@ public class MethodCallOperator {
|
|||
public Object perform(Calendar calendar, TypedOperand operand) {
|
||||
return calendar.get(Calendar.MINUTE);
|
||||
}
|
||||
}, EdmInt32.getInstance(), EdmDateTimeOffset.getInstance(), EdmTimeOfDay.getInstance());
|
||||
}, primInt32, primDateTimeOffset, primTimeOfDay);
|
||||
}
|
||||
|
||||
public VisitorOperand second() throws ODataApplicationException {
|
||||
|
@ -222,7 +251,7 @@ public class MethodCallOperator {
|
|||
public Object perform(Calendar calendar, TypedOperand operand) {
|
||||
return calendar.get(Calendar.SECOND);
|
||||
}
|
||||
}, EdmInt32.getInstance(), EdmDateTimeOffset.getInstance(), EdmTimeOfDay.getInstance());
|
||||
}, primInt32, primDateTimeOffset, primTimeOfDay);
|
||||
}
|
||||
|
||||
public VisitorOperand fractionalseconds() throws ODataApplicationException {
|
||||
|
@ -236,7 +265,7 @@ public class MethodCallOperator {
|
|||
return new BigDecimal(calendar.get(Calendar.MILLISECOND)).divide(BigDecimal.valueOf(1000));
|
||||
}
|
||||
}
|
||||
}, EdmDecimal.getInstance(), EdmDateTimeOffset.getInstance(), EdmTimeOfDay.getInstance());
|
||||
}, primDecimal, primDateTimeOffset, primTimeOfDay);
|
||||
}
|
||||
|
||||
public VisitorOperand round() throws ODataApplicationException {
|
||||
|
@ -290,13 +319,13 @@ public class MethodCallOperator {
|
|||
if (operand.is(expectedTypes)) {
|
||||
if (!operand.isNull()) {
|
||||
Calendar calendar = null;
|
||||
if (operand.is(EdmDate.getInstance())) {
|
||||
if (operand.is(primDate)) {
|
||||
calendar = operand.getTypedValue(Calendar.class);
|
||||
} else if (operand.is(EdmDateTimeOffset.getInstance())) {
|
||||
} else if (operand.is(primDateTimeOffset)) {
|
||||
final Timestamp timestamp = operand.getTypedValue(Timestamp.class);
|
||||
calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
||||
calendar.setTimeInMillis(timestamp.getTime());
|
||||
} else if (operand.is(EdmTimeOfDay.getInstance())) {
|
||||
} else if (operand.is(primTimeOfDay)) {
|
||||
calendar = operand.getTypedValue(Calendar.class);
|
||||
} else {
|
||||
throw new ODataApplicationException("Invalid type", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
|
||||
|
@ -327,7 +356,7 @@ public class MethodCallOperator {
|
|||
TypedOperand operand = param.asTypedOperand();
|
||||
if (operand.isNull()) {
|
||||
result.add(null);
|
||||
} else if (operand.is(EdmString.getInstance())) {
|
||||
} else if (operand.is(primString)) {
|
||||
result.add(operand.getTypedValue(String.class));
|
||||
} else {
|
||||
throw new ODataApplicationException("Invalid parameter. Expected Edm.String", HttpStatusCode.BAD_REQUEST
|
||||
|
|
|
@ -23,14 +23,26 @@ import java.math.BigDecimal;
|
|||
import java.math.BigInteger;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmBoolean;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.TypedOperand;
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.VisitorOperand;
|
||||
|
||||
public class UnaryOperator {
|
||||
|
||||
protected static final OData oData;
|
||||
protected static final EdmPrimitiveType primBoolean;
|
||||
protected static final EdmPrimitiveType primDuration;
|
||||
|
||||
static {
|
||||
oData = OData.newInstance();
|
||||
primBoolean = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean);
|
||||
primDuration = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Duration);
|
||||
}
|
||||
|
||||
final private TypedOperand operand;
|
||||
|
||||
public UnaryOperator(VisitorOperand operand) throws ODataApplicationException {
|
||||
|
@ -42,7 +54,7 @@ public class UnaryOperator {
|
|||
return operand;
|
||||
} else if (operand.isIntegerType()) {
|
||||
return new TypedOperand(operand.getTypedValue(BigInteger.class).negate(), operand.getType());
|
||||
} else if (operand.isDecimalType() || operand.is(EdmDuration.getInstance())) {
|
||||
} else if (operand.isDecimalType() || operand.is(primDuration)) {
|
||||
return new TypedOperand(operand.getTypedValue(BigDecimal.class).negate(), operand.getType());
|
||||
} else {
|
||||
throw new ODataApplicationException("Unsupported type", HttpStatusCode.BAD_REQUEST.getStatusCode(),
|
||||
|
@ -53,7 +65,7 @@ public class UnaryOperator {
|
|||
public VisitorOperand notOperation() throws ODataApplicationException {
|
||||
if (operand.isNull()) {
|
||||
return operand;
|
||||
} else if (operand.is(EdmBoolean.getInstance())) {
|
||||
} else if (operand.is(primBoolean)) {
|
||||
return new TypedOperand(!operand.getTypedValue(Boolean.class), operand.getType());
|
||||
} else {
|
||||
throw new ODataApplicationException("Unsupported type", HttpStatusCode.BAD_REQUEST.getStatusCode(),
|
||||
|
|
|
@ -18,11 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.server.tecsvc.processor.queryoptions.expression.primitive;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
|
||||
|
||||
public final class EdmNull extends SingletonPrimitiveType {
|
||||
public final class EdmNull implements EdmPrimitiveType {
|
||||
|
||||
private static final EdmNull instance = new EdmNull();
|
||||
|
||||
|
@ -34,8 +36,88 @@ public final class EdmNull extends SingletonPrimitiveType {
|
|||
public Class<?> getDefaultType() {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
protected String uriPrefix = "";
|
||||
|
||||
protected String uriSuffix = "";
|
||||
|
||||
@Override
|
||||
public FullQualifiedName getFullQualifiedName() {
|
||||
return new FullQualifiedName(getNamespace(), getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(final EdmPrimitiveType primitiveType) {
|
||||
return equals(primitiveType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
|
||||
final Boolean isUnicode) {
|
||||
|
||||
try {
|
||||
valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, getDefaultType());
|
||||
return true;
|
||||
} catch (final EdmPrimitiveTypeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> T valueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value == null) {
|
||||
if (isNullable != null && !isNullable) {
|
||||
throw new EdmPrimitiveTypeException("The literal 'null' is not allowed.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return internalValueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String valueToString(final Object value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
if (value == null) {
|
||||
if (isNullable != null && !isNullable) {
|
||||
throw new EdmPrimitiveTypeException("The value NULL is not allowed.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return internalValueToString(value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toUriLiteral(final String literal) {
|
||||
return literal == null ? null :
|
||||
uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
|
||||
if (literal == null) {
|
||||
return null;
|
||||
} else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) {
|
||||
return literal;
|
||||
} else if (literal.length() >= uriPrefix.length() + uriSuffix.length()
|
||||
&& literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) {
|
||||
|
||||
return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
|
||||
} else {
|
||||
throw new EdmPrimitiveTypeException("The literal '" + literal + "' has illegal content.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new FullQualifiedName(getNamespace(), getName()).getFullQualifiedNameAsString();
|
||||
}
|
||||
|
||||
protected <T> T internalValueOfString(String value, Boolean isNullable, Integer maxLength, Integer precision,
|
||||
Integer scale, Boolean isUnicode, Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
if (!value.equals("null")) {
|
||||
|
@ -49,10 +131,34 @@ public final class EdmNull extends SingletonPrimitiveType {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> String internalValueToString(T value, Boolean isNullable, Integer maxLength, Integer precision,
|
||||
Integer scale, Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return this == obj || obj != null && getClass() == obj.getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return EDM_NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getClass().getSimpleName().substring(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmTypeKind getKind() {
|
||||
return EdmTypeKind.PRIMITIVE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,34 +24,26 @@ import java.util.Locale;
|
|||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmBindingTarget;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmBoolean;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.uri.queryoption.FilterOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.ExpressionVisitorImpl;
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.TypedOperand;
|
||||
import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.VisitorOperand;
|
||||
|
||||
public class FilterHandler {
|
||||
|
||||
protected static final OData oData;
|
||||
protected static final EdmPrimitiveType primBoolean;
|
||||
|
||||
static {
|
||||
oData = OData.newInstance();
|
||||
primBoolean = oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean);
|
||||
}
|
||||
|
||||
public static void applyFilterSystemQuery(FilterOption filterOption, EntitySet entitySet,
|
||||
EdmBindingTarget edmEntitySet) throws ODataApplicationException {
|
||||
|
@ -68,7 +60,7 @@ public class FilterHandler {
|
|||
.accept(new ExpressionVisitorImpl(iter.next(), edmEntitySet));
|
||||
final TypedOperand typedOperand = operand.asTypedOperand();
|
||||
|
||||
if (!(typedOperand.is(EdmBoolean.getInstance())
|
||||
if (!(typedOperand.is(primBoolean)
|
||||
&& Boolean.TRUE.equals(typedOperand.getTypedValue(Boolean.class)))) {
|
||||
iter.remove();
|
||||
}
|
||||
|
|
|
@ -25,10 +25,10 @@ import java.util.Locale;
|
|||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.core.Encoder;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SkipTokenOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
|
||||
import org.apache.olingo.server.tecsvc.Encoder;
|
||||
|
||||
public class ServerSidePagingHandler {
|
||||
private static final int MAX_PAGE_SIZE = 10;
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
|||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
|
@ -615,7 +614,7 @@ public class ODataJsonSerializerTest {
|
|||
public void primitivePropertyNull() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString");
|
||||
final Property property = new PropertyImpl("Edm.String", edmProperty.getName(), ValueType.PRIMITIVE, null);
|
||||
final Property property = new Property("Edm.String", edmProperty.getName(), ValueType.PRIMITIVE, null);
|
||||
serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
|
||||
PrimitiveSerializerOptions.with()
|
||||
.contextURL(ContextURL.with()
|
||||
|
|
|
@ -33,9 +33,6 @@ import org.apache.olingo.commons.api.edm.EdmEntityType;
|
|||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.server.api.uri.UriParameter;
|
||||
import org.apache.olingo.server.sample.edmprovider.CarsEdmProvider;
|
||||
|
||||
|
@ -97,37 +94,37 @@ public class DataProvider {
|
|||
}
|
||||
|
||||
private EntitySet createCars() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl()
|
||||
entitySet.getEntities().add(new Entity()
|
||||
.addProperty(createPrimitive("Id", 1))
|
||||
.addProperty(createPrimitive("Model", "F1 W03"))
|
||||
.addProperty(createPrimitive("ModelYear", "2012"))
|
||||
.addProperty(createPrimitive("Price", 189189.43))
|
||||
.addProperty(createPrimitive("Currency", "EUR")));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl()
|
||||
entitySet.getEntities().add(new Entity()
|
||||
.addProperty(createPrimitive("Id", 2))
|
||||
.addProperty(createPrimitive("Model", "F1 W04"))
|
||||
.addProperty(createPrimitive("ModelYear", "2013"))
|
||||
.addProperty(createPrimitive("Price", 199999.99))
|
||||
.addProperty(createPrimitive("Currency", "EUR")));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl()
|
||||
entitySet.getEntities().add(new Entity()
|
||||
.addProperty(createPrimitive("Id", 3))
|
||||
.addProperty(createPrimitive("Model", "F2012"))
|
||||
.addProperty(createPrimitive("ModelYear", "2012"))
|
||||
.addProperty(createPrimitive("Price", 137285.33))
|
||||
.addProperty(createPrimitive("Currency", "EUR")));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl()
|
||||
entitySet.getEntities().add(new Entity()
|
||||
.addProperty(createPrimitive("Id", 4))
|
||||
.addProperty(createPrimitive("Model", "F2013"))
|
||||
.addProperty(createPrimitive("ModelYear", "2013"))
|
||||
.addProperty(createPrimitive("Price", 145285.00))
|
||||
.addProperty(createPrimitive("Currency", "EUR")));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl()
|
||||
entitySet.getEntities().add(new Entity()
|
||||
.addProperty(createPrimitive("Id", 5))
|
||||
.addProperty(createPrimitive("Model", "F1 W02"))
|
||||
.addProperty(createPrimitive("ModelYear", "2011"))
|
||||
|
@ -141,14 +138,14 @@ public class DataProvider {
|
|||
}
|
||||
|
||||
private EntitySet createManufacturers() {
|
||||
EntitySet entitySet = new EntitySetImpl();
|
||||
EntitySet entitySet = new EntitySet();
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl()
|
||||
entitySet.getEntities().add(new Entity()
|
||||
.addProperty(createPrimitive("Id", 1))
|
||||
.addProperty(createPrimitive("Name", "Star Powered Racing"))
|
||||
.addProperty(createAddress("Star Street 137", "Stuttgart", "70173", "Germany")));
|
||||
|
||||
entitySet.getEntities().add(new EntityImpl()
|
||||
entitySet.getEntities().add(new Entity()
|
||||
.addProperty(createPrimitive("Id", 2))
|
||||
.addProperty(createPrimitive("Name", "Horse Powered Racing"))
|
||||
.addProperty(createAddress("Horse Street 1", "Maranello", "41053", "Italy")));
|
||||
|
@ -165,10 +162,10 @@ public class DataProvider {
|
|||
addressProperties.add(createPrimitive("City", city));
|
||||
addressProperties.add(createPrimitive("ZipCode", zipCode));
|
||||
addressProperties.add(createPrimitive("Country", country));
|
||||
return new PropertyImpl(null, "Address", ValueType.COMPLEX, addressProperties);
|
||||
return new Property(null, "Address", ValueType.COMPLEX, addressProperties);
|
||||
}
|
||||
|
||||
private Property createPrimitive(final String name, final Object value) {
|
||||
return new PropertyImpl(null, name, ValueType.PRIMITIVE, value);
|
||||
return new Property(null, name, ValueType.PRIMITIVE, value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue