You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/07/17 12:11:57 UTC
[8/8] isis git commit: ISIS-1174: fix for the "objects of type"
resource, along with new screencast.
ISIS-1174: fix for the "objects of type" resource, along with new screencast.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/d159f02c
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/d159f02c
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/d159f02c
Branch: refs/heads/master
Commit: d159f02cdb3a3fed8dc357d94a1d8cb6a7ceffea
Parents: e1c1a53
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Jul 17 11:11:30 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Jul 17 11:11:30 2015 +0100
----------------------------------------------------------------------
.../src/main/asciidoc/screencasts.adoc | 11 ++--
.../DomainObjectResourceServerside.java | 10 ++--
.../resources/ObjectAdapterUpdateHelper.java | 56 ++++++++++++--------
3 files changed, 48 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/d159f02c/adocs/documentation/src/main/asciidoc/screencasts.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/screencasts.adoc b/adocs/documentation/src/main/asciidoc/screencasts.adoc
index 3714490..909c933 100644
--- a/adocs/documentation/src/main/asciidoc/screencasts.adoc
+++ b/adocs/documentation/src/main/asciidoc/screencasts.adoc
@@ -160,12 +160,17 @@ _How to customize the Wicket viewer, integrating the (non-ASF) http://github.com
|Using Chrome Tools +
-_Interacting with the REST API using Chrome Plugins_
-
+_Using Chrome plugins to invoke an action through the REST API_
|video::_-TOvVYWCHc[youtube,width="420px",height="236px"]
-
+
+|Creating objects using the REST API
+
+_Posting to the "Objects of Type" resource"_
+
+|video::VmvhACyA2ZI[youtube,width="420px",height="236px"]
+
|===
http://git-wip-us.apache.org/repos/asf/isis/blob/d159f02c/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java
----------------------------------------------------------------------
diff --git a/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java b/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java
index 1c09e77..3c7b039 100644
--- a/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java
+++ b/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainObjectResourceServerside.java
@@ -83,12 +83,12 @@ public class DomainObjectResourceServerside extends ResourceAbstract implements
final ObjectAdapterUpdateHelper updateHelper = new ObjectAdapterUpdateHelper(getResourceContext(), objectAdapter);
- final JsonRepresentation propertiesList = objectRepr.getArrayEnsured("members[objectMemberType=property]");
- if (propertiesList == null) {
- throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Could not find properties list (no members[objectMemberType=property]); got %s", objectRepr);
+ final JsonRepresentation membersMap = objectRepr.getMap("members");
+ if (membersMap == null) {
+ throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Could not find members map; got %s", objectRepr);
}
- if (!updateHelper.copyOverProperties(propertiesList)) {
+ if (!updateHelper.copyOverProperties(membersMap, ObjectAdapterUpdateHelper.Intent.PERSISTING_NEW)) {
throw RestfulObjectsApplicationException.createWithBody(HttpStatusCode.BAD_REQUEST, objectRepr, "Illegal property value");
}
@@ -148,7 +148,7 @@ public class DomainObjectResourceServerside extends ResourceAbstract implements
final ObjectAdapter objectAdapter = getObjectAdapterElseThrowNotFound(domainType, instanceId);
final ObjectAdapterUpdateHelper updateHelper = new ObjectAdapterUpdateHelper(getResourceContext(), objectAdapter);
- if (!updateHelper.copyOverProperties(argRepr)) {
+ if (!updateHelper.copyOverProperties(argRepr, ObjectAdapterUpdateHelper.Intent.UPDATE_EXISTING)) {
throw RestfulObjectsApplicationException.createWithBody(HttpStatusCode.BAD_REQUEST, argRepr, "Illegal property value");
}
http://git-wip-us.apache.org/repos/asf/isis/blob/d159f02c/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/ObjectAdapterUpdateHelper.java
----------------------------------------------------------------------
diff --git a/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/ObjectAdapterUpdateHelper.java b/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/ObjectAdapterUpdateHelper.java
index 6236695..4b41b3c 100644
--- a/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/ObjectAdapterUpdateHelper.java
+++ b/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/ObjectAdapterUpdateHelper.java
@@ -46,8 +46,17 @@ public class ObjectAdapterUpdateHelper {
}
- public boolean copyOverProperties(
- final JsonRepresentation propertiesList) {
+ enum Intent {
+ UPDATE_EXISTING,
+ PERSISTING_NEW;
+ private boolean shouldValidate() {
+ return this == UPDATE_EXISTING;
+ }
+ }
+
+ boolean copyOverProperties(
+ final JsonRepresentation propertiesMap,
+ final Intent intent) {
final ObjectSpecification objectSpec = objectAdapter.getSpecification();
final List<ObjectAssociation> properties = objectSpec.getAssociations(Contributed.EXCLUDED, ObjectAssociation.Filters.PROPERTIES);
@@ -58,7 +67,7 @@ public class ObjectAdapterUpdateHelper {
final OneToOneAssociation property = (OneToOneAssociation) association;
final ObjectSpecification propertySpec = property.getSpecification();
final String id = property.getId();
- final JsonRepresentation propertyRepr = propertiesList.getRepresentation(id);
+ final JsonRepresentation propertyRepr = propertiesMap.getRepresentation(id);
final Consent visibility = property.isVisible(resourceContext.getAuthenticationSession() , objectAdapter, resourceContext.getWhere());
final Consent usability = property.isUsable(resourceContext.getAuthenticationSession() , objectAdapter, resourceContext.getWhere());
@@ -69,10 +78,11 @@ public class ObjectAdapterUpdateHelper {
if(!valueProvided) {
// no value provided
-
- if(invisible || disabled) {
- // that's ok, indeed expected
- continue;
+ if(intent.shouldValidate()) {
+ if(invisible || disabled) {
+ // that's ok, indeed expected
+ continue;
+ }
}
if (!property.isMandatory()) {
// optional, so also not a problem
@@ -80,30 +90,34 @@ public class ObjectAdapterUpdateHelper {
}
// otherwise, is an error.
- final String invalidReason = propertiesList.getString("x-ro-invalidReason");
+ final String invalidReason = propertiesMap.getString("x-ro-invalidReason");
if(invalidReason != null) {
- propertiesList.mapPut("x-ro-invalidReason", invalidReason + "; " + property.getName());
+ propertiesMap.mapPut("x-ro-invalidReason", invalidReason + "; " + property.getName());
} else {
- propertiesList.mapPut("x-ro-invalidReason", "Mandatory field(s) missing: " + property.getName());
+ propertiesMap.mapPut("x-ro-invalidReason", "Mandatory field(s) missing: " + property.getName());
}
allOk = false;
continue;
} else {
- // value has been provided
- if (invisible) {
- // silently ignore; don't want to acknowledge the existence of this property to the caller
- continue;
- }
- if (disabled) {
- // not allowed to update
- propertyRepr.mapPut("invalidReason", usability.getReason());
- allOk = false;
- continue;
+ if(intent.shouldValidate()) {
+ // value has been provided
+ if (invisible) {
+ // silently ignore; don't want to acknowledge the
+ // existence of this property to the caller
+ continue;
+ }
+ if (disabled) {
+ // not allowed to update
+ propertyRepr.mapPut("invalidReason", usability.getReason());
+ allOk = false;
+ continue;
+ }
}
- // ok, we have a value, and the property is not invisible, and is not disabled
+ // ok, we have a value, and
+ // (if validating) then the property is not invisible, and is not disabled
final ObjectAdapter valueAdapter;
try {
valueAdapter = new JsonParserHelper(resourceContext, propertySpec).objectAdapterFor(propertyRepr);