[OLINGO-264] Introducing data and domain objects to let annotate delta links

This commit is contained in:
Francesco Chicchiriccò 2014-05-06 11:00:30 +02:00
parent 70cdaef515
commit 4a07d59b4d
11 changed files with 223 additions and 35 deletions

View File

@ -26,9 +26,9 @@ import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.op.AbstractODataBinder;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.domain.v4.ODataDeletedEntity;
import org.apache.olingo.commons.api.data.DeletedEntity;
import org.apache.olingo.commons.api.data.Delta;
import org.apache.olingo.commons.api.domain.v4.ODataDeltaLink;
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.LinkedComplexValue;
@ -40,16 +40,17 @@ import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.domain.v4.ODataDeletedEntity.Reason;
import org.apache.olingo.commons.api.domain.v4.ODataDelta;
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
import org.apache.olingo.commons.api.domain.v4.ODataLinkedComplexValue;
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.core.domain.v4.ODataDeletedEntityImpl;
import org.apache.olingo.commons.core.domain.v4.ODataDeltaLinkImpl;
import org.apache.olingo.commons.core.data.EnumValueImpl;
import org.apache.olingo.commons.core.data.LinkedComplexValueImpl;
import org.apache.olingo.commons.core.domain.v4.ODataDeletedEntityImpl;
import org.apache.olingo.commons.core.domain.v4.ODataDeltaLinkImpl;
import org.apache.olingo.commons.core.domain.v4.ODataPropertyImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.commons.core.op.ResourceFactory;
@ -240,15 +241,15 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
add(delta, getODataEntity(
new ResWrap<Entity>(resource.getContextURL(), resource.getMetadataETag(), entityResource)));
}
for (ODataDeletedEntity deletedEntity : resource.getPayload().getDeletedEntities()) {
for (DeletedEntity deletedEntity : resource.getPayload().getDeletedEntities()) {
final ODataDeletedEntityImpl impl = new ODataDeletedEntityImpl();
impl.setId(URIUtils.getURI(base, deletedEntity.getId()));
impl.setReason(deletedEntity.getReason());
impl.setReason(Reason.valueOf(deletedEntity.getReason().name()));
delta.getDeletedEntities().add(impl);
}
for (ODataDeltaLink link : resource.getPayload().getAddedLinks()) {
for (DeltaLink link : resource.getPayload().getAddedLinks()) {
final ODataDeltaLinkImpl impl = new ODataDeltaLinkImpl();
impl.setRelationship(link.getRelationship());
impl.setSource(URIUtils.getURI(base, link.getSource()));
@ -256,7 +257,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
delta.getAddedLinks().add(impl);
}
for (ODataDeltaLink link : resource.getPayload().getDeletedLinks()) {
for (DeltaLink link : resource.getPayload().getDeletedLinks()) {
final ODataDeltaLinkImpl impl = new ODataDeltaLinkImpl();
impl.setRelationship(link.getRelationship());
impl.setSource(URIUtils.getURI(base, link.getSource()));

View File

@ -0,0 +1,36 @@
/*
* 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.api.data;
import java.net.URI;
public interface DeletedEntity {
enum Reason {
deleted,
changed;
}
URI getId();
Reason getReason();
}

View File

@ -18,16 +18,14 @@
*/
package org.apache.olingo.commons.api.data;
import org.apache.olingo.commons.api.domain.v4.ODataDeletedEntity;
import org.apache.olingo.commons.api.domain.v4.ODataDeltaLink;
import java.util.List;
public interface Delta extends EntitySet {
List<ODataDeletedEntity> getDeletedEntities();
List<DeletedEntity> getDeletedEntities();
List<ODataDeltaLink> getAddedLinks();
List<DeltaLink> getAddedLinks();
List<ODataDeltaLink> getDeletedLinks();
List<DeltaLink> getDeletedLinks();
}

View File

@ -0,0 +1,36 @@
/*
* 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.api.data;
import java.net.URI;
public interface DeltaLink extends Annotatable {
URI getSource();
void setSource(URI source);
String getRelationship();
void setRelationship(String relationship);
URI getTarget();
void setTarget(URI target);
}

View File

@ -20,7 +20,7 @@ package org.apache.olingo.commons.api.domain.v4;
import java.net.URI;
public interface ODataDeltaLink {
public interface ODataDeltaLink extends ODataAnnotatatable {
URI getSource();

View File

@ -20,8 +20,6 @@ package org.apache.olingo.commons.core.data;
import com.fasterxml.aalto.stax.InputFactoryImpl;
import org.apache.olingo.commons.core.data.v4.AtomDeltaImpl;
import org.apache.olingo.commons.core.domain.v4.ODataDeltaLinkImpl;
import org.apache.olingo.commons.core.domain.v4.ODataDeletedEntityImpl;
import java.io.InputStream;
import java.net.URI;
import java.text.ParseException;
@ -35,7 +33,7 @@ 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.CollectionValue;
import org.apache.olingo.commons.api.domain.v4.ODataDeletedEntity.Reason;
import org.apache.olingo.commons.api.data.DeletedEntity.Reason;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Value;
@ -421,7 +419,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
} 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 ODataDeletedEntityImpl deletedEntity = new ODataDeletedEntityImpl();
final DeletedEntityImpl deletedEntity = new DeletedEntityImpl();
final Attribute ref = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REF));
if (ref != null) {
@ -436,7 +434,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
} else if (linkQName.equals(event.asStartElement().getName())
|| deletedLinkQName.equals(event.asStartElement().getName())) {
final ODataDeltaLinkImpl link = new ODataDeltaLinkImpl();
final DeltaLinkImpl link = new DeltaLinkImpl();
final Attribute source = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_SOURCE));
if (source != null) {

View File

@ -0,0 +1,50 @@
/*
* 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.net.URI;
import org.apache.olingo.commons.api.data.DeletedEntity;
public class DeletedEntityImpl extends AbstractAnnotatedObject implements DeletedEntity {
private static final long serialVersionUID = 2075093398299488510L;
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;
}
}

View File

@ -0,0 +1,64 @@
/*
* 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.net.URI;
import org.apache.olingo.commons.api.data.DeltaLink;
public class DeltaLinkImpl extends AbstractAnnotatedObject implements DeltaLink {
private static final long serialVersionUID = 581329273399308799L;
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;
}
}

View File

@ -19,8 +19,6 @@
package org.apache.olingo.commons.core.data;
import org.apache.olingo.commons.core.data.v4.JSONDeltaImpl;
import org.apache.olingo.commons.core.domain.v4.ODataDeltaLinkImpl;
import org.apache.olingo.commons.core.domain.v4.ODataDeletedEntityImpl;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@ -78,14 +76,11 @@ public class JSONDeltaDeserializer extends AbstractJsonDeserializer<JSONDeltaImp
});
delta.getEntities().add(entity.getPayload());
} else if (itemContextURL.isDeltaDeletedEntity()) {
delta.getDeletedEntities().
add(parser.getCodec().treeToValue(item, ODataDeletedEntityImpl.class));
delta.getDeletedEntities().add(parser.getCodec().treeToValue(item, DeletedEntityImpl.class));
} else if (itemContextURL.isDeltaLink()) {
delta.getAddedLinks().
add(parser.getCodec().treeToValue(item, ODataDeltaLinkImpl.class));
delta.getAddedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class));
} else if (itemContextURL.isDeltaDeletedLink()) {
delta.getDeletedLinks().
add(parser.getCodec().treeToValue(item, ODataDeltaLinkImpl.class));
delta.getDeletedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class));
}
}
}

View File

@ -20,33 +20,33 @@ package org.apache.olingo.commons.core.data.v4;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.commons.api.domain.v4.ODataDeletedEntity;
import org.apache.olingo.commons.api.data.DeletedEntity;
import org.apache.olingo.commons.api.data.Delta;
import org.apache.olingo.commons.api.domain.v4.ODataDeltaLink;
import org.apache.olingo.commons.api.data.DeltaLink;
import org.apache.olingo.commons.core.data.AbstractEntitySet;
public abstract class AbstractDelta extends AbstractEntitySet implements Delta {
private static final long serialVersionUID = 4576771708961553195L;
private final List<ODataDeletedEntity> deletedEntities = new ArrayList<ODataDeletedEntity>();
private final List<DeletedEntity> deletedEntities = new ArrayList<DeletedEntity>();
private final List<ODataDeltaLink> addedLinks = new ArrayList<ODataDeltaLink>();
private final List<DeltaLink> addedLinks = new ArrayList<DeltaLink>();
private final List<ODataDeltaLink> deletedLinks = new ArrayList<ODataDeltaLink>();
private final List<DeltaLink> deletedLinks = new ArrayList<DeltaLink>();
@Override
public List<ODataDeletedEntity> getDeletedEntities() {
public List<DeletedEntity> getDeletedEntities() {
return deletedEntities;
}
@Override
public List<ODataDeltaLink> getAddedLinks() {
public List<DeltaLink> getAddedLinks() {
return addedLinks;
}
@Override
public List<ODataDeltaLink> getDeletedLinks() {
public List<DeltaLink> getDeletedLinks() {
return deletedLinks;
}
}

View File

@ -19,7 +19,10 @@
package org.apache.olingo.commons.core.domain.v4;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.commons.api.domain.ODataItem;
import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
import org.apache.olingo.commons.api.domain.v4.ODataDeltaLink;
public class ODataDeltaLinkImpl extends ODataItem implements ODataDeltaLink {
@ -32,6 +35,8 @@ public class ODataDeltaLinkImpl extends ODataItem implements ODataDeltaLink {
private URI target;
private final List<ODataAnnotation> annotations = new ArrayList<ODataAnnotation>();
public ODataDeltaLinkImpl() {
super(null);
}
@ -66,4 +71,9 @@ public class ODataDeltaLinkImpl extends ODataItem implements ODataDeltaLink {
this.target = target;
}
@Override
public List<ODataAnnotation> getAnnotations() {
return annotations;
}
}