incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1177197 - in /incubator/isis/trunk/framework/viewer/json: json-applib/src/main/java/org/apache/isis/viewer/json/applib/ json-applib/src/test/java/org/apache/isis/viewer/json/applib/ json-viewer/src/main/java/org/apache/isis/viewer/json/vie...
Date Thu, 29 Sep 2011 07:59:05 GMT
Author: danhaywood
Date: Thu Sep 29 07:59:04 2011
New Revision: 1177197

URL: http://svn.apache.org/viewvc?rev=1177197&view=rev
Log:
ISIS-109: started refactoring so that representation builders are looked up by media type
(eventually: will be taken from Accept header)

Added:
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/DomainObjectTypedReprBuilderFactory.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilder.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderAbstract.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactory.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryAbstract.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryRegistry.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/AbstractResourceHelper.java
Modified:
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationType.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RepresentationTypeTest_getMediaType_lookup.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/JsonApplication.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectReprBuilder.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectResourceServerside.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceHelper.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceServerside.java
    incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceHelper.java

Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationType.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationType.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationType.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/RepresentationType.java
Thu Sep 29 07:59:04 2011
@@ -56,7 +56,11 @@ public enum RepresentationType {
     public final MediaType getMediaType() {
         return mediaType;
     }
-    
+
+    public String getMediaTypeProfile() {
+        return getMediaType().getParameters().get("profile");
+    }
+
     public Class<? extends JsonRepresentation> getRepresentationClass() {
         return representationClass;
     }
@@ -91,6 +95,7 @@ public enum RepresentationType {
             }
         };
     }
+
     
     
 }

Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RepresentationTypeTest_getMediaType_lookup.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RepresentationTypeTest_getMediaType_lookup.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RepresentationTypeTest_getMediaType_lookup.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RepresentationTypeTest_getMediaType_lookup.java
Thu Sep 29 07:59:04 2011
@@ -1,6 +1,7 @@
 package org.apache.isis.viewer.json.applib;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertThat;
 
@@ -29,4 +30,10 @@ public class RepresentationTypeTest_getM
         assertThat(RepresentationType.lookup((MediaType)null), is(RepresentationType.GENERIC));
     }
 
+    @Test
+    public void getMediaTypeProfile() {
+        assertThat(RepresentationType.CAPABILITIES.getMediaTypeProfile(), is("http://restfulobjects.org/profiles/capabilities"));
+        assertThat(RepresentationType.GENERIC.getMediaTypeProfile(), is(nullValue()));
+    }
+
 }

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/JsonApplication.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/JsonApplication.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/JsonApplication.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/JsonApplication.java
Thu Sep 29 07:59:04 2011
@@ -28,14 +28,21 @@ import org.apache.isis.viewer.json.viewe
 public class JsonApplication extends AbstractJaxRsApplication {
 
     public JsonApplication() {
-        addSingleton(new HomePageResourceServerside());
-        addSingleton(new DomainTypeResourceServerside());
-        addSingleton(new UserResourceServerside());
-        addSingleton(new DomainObjectResourceServerside());
-        addSingleton(new DomainServiceResourceServerside());
-        addSingleton(new CapabilitiesResourceServerside());
+        addClass(HomePageResourceServerside.class);
+        addClass(DomainTypeResourceServerside.class);
+        addClass(UserResourceServerside.class);
+        addClass(DomainObjectResourceServerside.class);
+        addClass(DomainServiceResourceServerside.class);
+        addClass(CapabilitiesResourceServerside.class);
+        
         addSingleton(new JsonApplicationExceptionMapper());
+        
+        // TODO: doesn't get injected
+        // addSingleton(new TypedReprBuilderFactoryRegistry());
+        
+        // TODO: idea being to remove the init()
         // addSingleton(new PreProcessInterceptorForIsisSession());
     }
 
+
 }

Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/DomainObjectTypedReprBuilderFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/DomainObjectTypedReprBuilderFactory.java?rev=1177197&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/DomainObjectTypedReprBuilderFactory.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/DomainObjectTypedReprBuilderFactory.java
Thu Sep 29 07:59:04 2011
@@ -0,0 +1,19 @@
+package org.apache.isis.viewer.json.viewer.representations;
+
+import org.apache.isis.viewer.json.applib.RepresentationType;
+import org.apache.isis.viewer.json.viewer.ResourceContext;
+import org.apache.isis.viewer.json.viewer.resources.domainobjects.DomainObjectReprBuilder;
+
+class DomainObjectTypedReprBuilderFactory extends TypedReprBuilderFactoryAbstract {
+
+    public DomainObjectTypedReprBuilderFactory() {
+        super(RepresentationType.DOMAIN_OBJECT);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> TypedReprBuilder<T> newBuilder(ResourceContext resourceContext,
Class<T> cls) {
+        return (TypedReprBuilder<T>) DomainObjectReprBuilder.newBuilder(resourceContext);
+    }
+    
+}
\ No newline at end of file

Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilder.java?rev=1177197&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilder.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilder.java
Thu Sep 29 07:59:04 2011
@@ -0,0 +1,10 @@
+package org.apache.isis.viewer.json.viewer.representations;
+
+
+public interface TypedReprBuilder<T> extends ReprBuilder {
+
+    TypedReprBuilder<T> withSelf();
+
+    TypedReprBuilder<T> with(T t);
+
+}

Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderAbstract.java?rev=1177197&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderAbstract.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderAbstract.java
Thu Sep 29 07:59:04 2011
@@ -0,0 +1,17 @@
+package org.apache.isis.viewer.json.viewer.representations;
+
+import org.apache.isis.viewer.json.viewer.ResourceContext;
+
+public abstract class TypedReprBuilderAbstract<T> implements TypedReprBuilder<T>
{
+
+    private final ResourceContext resourceContext;
+
+    public TypedReprBuilderAbstract(ResourceContext resourceContext) {
+        this.resourceContext = resourceContext;
+    }
+    
+    public ResourceContext getResourceContext() {
+        return resourceContext;
+    }
+
+}

Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactory.java?rev=1177197&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactory.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactory.java
Thu Sep 29 07:59:04 2011
@@ -0,0 +1,12 @@
+package org.apache.isis.viewer.json.viewer.representations;
+
+import org.apache.isis.viewer.json.applib.RepresentationType;
+import org.apache.isis.viewer.json.viewer.ResourceContext;
+
+public interface TypedReprBuilderFactory {
+
+    public abstract RepresentationType getRepresentationType();
+
+    public abstract <T> TypedReprBuilder<T> newBuilder(ResourceContext resourceContext,
Class<T> cls);
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryAbstract.java?rev=1177197&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryAbstract.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryAbstract.java
Thu Sep 29 07:59:04 2011
@@ -0,0 +1,19 @@
+package org.apache.isis.viewer.json.viewer.representations;
+
+import org.apache.isis.viewer.json.applib.RepresentationType;
+
+public abstract class TypedReprBuilderFactoryAbstract implements TypedReprBuilderFactory
{
+
+    private final RepresentationType representationType;
+
+    public TypedReprBuilderFactoryAbstract(RepresentationType representationType) {
+        this.representationType = representationType;
+    }
+    
+    @Override
+    public RepresentationType getRepresentationType() {
+        return representationType;
+    }
+
+    
+}

Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryRegistry.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryRegistry.java?rev=1177197&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryRegistry.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/representations/TypedReprBuilderFactoryRegistry.java
Thu Sep 29 07:59:04 2011
@@ -0,0 +1,49 @@
+/*
+ *  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.isis.viewer.json.viewer.representations;
+
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.isis.viewer.json.applib.RepresentationType;
+
+import com.google.common.collect.Maps;
+
+public class TypedReprBuilderFactoryRegistry {
+
+    private final Map<MediaType, TypedReprBuilderFactory> factoryByReprType = Maps.newHashMap();
+    
+    public TypedReprBuilderFactoryRegistry() {
+        registerDefaults();
+    }
+    
+    private void registerDefaults() {
+        register(new DomainObjectTypedReprBuilderFactory());
+    }
+
+    public void register(TypedReprBuilderFactory factory) {
+        final RepresentationType representationType = factory.getRepresentationType();
+        factoryByReprType.put(representationType.getMediaType(), factory);
+    }
+    
+    public TypedReprBuilderFactory locate(MediaType mediaType) {
+        return factoryByReprType.get(mediaType);
+    }
+}

Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/AbstractResourceHelper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/AbstractResourceHelper.java?rev=1177197&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/AbstractResourceHelper.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/AbstractResourceHelper.java
Thu Sep 29 07:59:04 2011
@@ -0,0 +1,44 @@
+/*
+ *  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.isis.viewer.json.viewer.resources;
+
+import org.apache.isis.viewer.json.viewer.ResourceContext;
+
+public class AbstractResourceHelper {
+
+    private final ResourceContext resourceContext;
+    private final String selfRef;
+    
+    public AbstractResourceHelper(ResourceContext resourceContext) {
+        this(resourceContext, null);
+    }
+
+    public AbstractResourceHelper(ResourceContext resourceContext, String selfRef) {
+        this.resourceContext = resourceContext;
+        this.selfRef = selfRef;
+    }
+
+    public ResourceContext getResourceContext() {
+        return resourceContext;
+    }
+    
+    public String getSelfRef() {
+        return selfRef;
+    }
+}

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstract.java
Thu Sep 29 07:59:04 2011
@@ -55,6 +55,7 @@ import org.apache.isis.viewer.json.viewe
 import org.apache.isis.viewer.json.viewer.ResourceContext;
 import org.apache.isis.viewer.json.viewer.representations.AbstractReprBuilder;
 import org.apache.isis.viewer.json.viewer.representations.ReprBuilder;
+import org.apache.isis.viewer.json.viewer.representations.TypedReprBuilderFactoryRegistry;
 import org.apache.isis.viewer.json.viewer.resources.domainobjects.DomainObjectReprBuilder;
 import org.apache.isis.viewer.json.viewer.util.OidUtils;
 import org.apache.isis.viewer.json.viewer.util.UrlDecoderUtils;
@@ -91,11 +92,11 @@ public abstract class ResourceAbstract {
         }
     }
 
+    // nb: SET is excluded; we simply flatten contributed actions.
+	public final static ActionType[] ACTION_TYPES = { ActionType.USER, ActionType.DEBUG, ActionType.EXPLORATION
};
 
-	public final static ActionType[] ACTION_TYPES = { ActionType.USER, ActionType.DEBUG, ActionType.EXPLORATION,
-    // SET is excluded; we simply flatten contributed actions.
-        };
-
+	// TODO: should inject this instead...
+	protected final static TypedReprBuilderFactoryRegistry BUILDER_REGISTRY = new TypedReprBuilderFactoryRegistry();
 
     @Context
     HttpHeaders httpHeaders;
@@ -122,7 +123,7 @@ public abstract class ResourceAbstract {
             new ResourceContext(httpHeaders, uriInfo, request, httpServletRequest, httpServletResponse,
securityContext, 
                     getOidStringifier(), getLocalization(), getAuthenticationSession(), getPersistenceSession(),
getAdapterManager());
     }
-
+    
     protected ResourceContext getResourceContext() {
         return resourceContext;
     }

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectReprBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectReprBuilder.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectReprBuilder.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectReprBuilder.java
Thu Sep 29 07:59:04 2011
@@ -34,11 +34,12 @@ import org.apache.isis.viewer.json.appli
 import org.apache.isis.viewer.json.viewer.ResourceContext;
 import org.apache.isis.viewer.json.viewer.representations.AbstractReprBuilder;
 import org.apache.isis.viewer.json.viewer.representations.LinkReprBuilder;
+import org.apache.isis.viewer.json.viewer.representations.TypedReprBuilder;
 import org.apache.isis.viewer.json.viewer.util.OidUtils;
 
 import com.google.common.base.Function;
 
-public class DomainObjectReprBuilder extends AbstractReprBuilder<DomainObjectReprBuilder>
{
+public class DomainObjectReprBuilder extends AbstractReprBuilder<DomainObjectReprBuilder>
implements TypedReprBuilder<ObjectAdapter>{
 
     public static DomainObjectReprBuilder newBuilder(ResourceContext resourceContext) {
         return new DomainObjectReprBuilder(resourceContext);
@@ -51,6 +52,7 @@ public class DomainObjectReprBuilder ext
     }
 
     private ObjectAdapterLinkToBuilder linkToBuilder;
+    private boolean includeSelf;
 
     public DomainObjectReprBuilder(ResourceContext resourceContext) {
         super(resourceContext);
@@ -66,9 +68,17 @@ public class DomainObjectReprBuilder ext
         return this;
     }
 
-    public DomainObjectReprBuilder withAdapter(ObjectAdapter objectAdapter) {
-        JsonRepresentation self = linkToBuilder.with(objectAdapter).linkToAdapter().build();
-        representation.mapPut("self", self);
+    @Override
+    public DomainObjectReprBuilder withSelf() {
+        this.includeSelf = true;
+        return this;
+    }
+
+    public DomainObjectReprBuilder with(ObjectAdapter objectAdapter) {
+        if(includeSelf) {
+            JsonRepresentation self = linkToBuilder.with(objectAdapter).linkToAdapter().build();
+            representation.mapPut("self", self);
+        }
 
         String title = objectAdapter.titleString();
         representation.mapPut("oid", OidUtils.getOidStr(resourceContext, objectAdapter));
@@ -152,7 +162,7 @@ public class DomainObjectReprBuilder ext
         return new Function<ObjectAdapter, JsonRepresentation>() {
             @Override
             public JsonRepresentation apply(ObjectAdapter adapter) {
-                return newBuilder(resourceContext).withAdapter(adapter).build();
+                return newBuilder(resourceContext).with(adapter).build();
             }
         };
     }
@@ -184,4 +194,5 @@ public class DomainObjectReprBuilder ext
 	}
 
 
+
 }
\ No newline at end of file

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectResourceServerside.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectResourceServerside.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectResourceServerside.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainObjectResourceServerside.java
Thu Sep 29 07:59:04 2011
@@ -17,6 +17,8 @@
 package org.apache.isis.viewer.json.viewer.resources.domainobjects;
 
 import java.io.InputStream;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
@@ -29,8 +31,10 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
 
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.version.Version;
 import org.apache.isis.core.metamodel.consent.Consent;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
@@ -41,15 +45,23 @@ import org.apache.isis.viewer.json.appli
 import org.apache.isis.viewer.json.applib.domainobjects.DomainObjectResource;
 import org.apache.isis.viewer.json.viewer.JsonApplicationException;
 import org.apache.isis.viewer.json.viewer.ResourceContext;
+import org.apache.isis.viewer.json.viewer.representations.AbstractReprBuilder;
+import org.apache.isis.viewer.json.viewer.representations.TypedReprBuilder;
+import org.apache.isis.viewer.json.viewer.representations.TypedReprBuilderFactory;
 
 @Path("/objects")
 public class DomainObjectResourceServerside extends DomainResourceAbstract implements
         DomainObjectResource {
-    
+
+    private static final DateFormat ETAG_FORMAT = 
+            new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+
     ////////////////////////////////////////////////////////////
     // domain object
     ////////////////////////////////////////////////////////////
     
+
+
     @GET
     @Path("/{oid}")
     @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_DOMAIN_OBJECT,
RestfulMediaType.APPLICATION_JSON_ERROR })
@@ -59,7 +71,22 @@ public class DomainObjectResourceServers
 
         final ObjectAdapter objectAdapter = getObjectAdapter(oidStr);
         
-        return object(objectAdapter);
+        final TypedReprBuilderFactory reprBuilderBuilder = 
+                BUILDER_REGISTRY.locate(RepresentationType.DOMAIN_OBJECT.getMediaType());
+        
+        final TypedReprBuilder<ObjectAdapter> repBuilder = 
+                reprBuilderBuilder.newBuilder(getResourceContext(), ObjectAdapter.class);
+
+        repBuilder.withSelf().with(objectAdapter);
+        
+        ResponseBuilder respBuilder = 
+                responseOfOk(RepresentationType.DOMAIN_OBJECT, Caching.NONE, repBuilder);
+        
+        Version version = objectAdapter.getVersion();
+        if (version != null && version.getTime() != null) {
+            respBuilder.tag(ETAG_FORMAT.format(version.getTime()));
+        }
+        return respBuilder.build();
     }
 
     @PUT

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java
Thu Sep 29 07:59:04 2011
@@ -67,14 +67,14 @@ public abstract class DomainResourceAbst
         ResourceContext resourceContext = getResourceContext();
         final AbstractReprBuilder<?> repBuilder =
                 DomainObjectReprBuilder.newBuilder(resourceContext)
-                        .withAdapter(objectAdapter);
+                        .with(objectAdapter);
 
         ResponseBuilder respBuilder = 
                 responseOfOk(RepresentationType.DOMAIN_OBJECT, Caching.NONE, repBuilder);
 
         Version version = objectAdapter.getVersion();
         if (version != null && version.getTime() != null) {
-            respBuilder.lastModified(version.getTime());
+            respBuilder.tag(""+version.getTime());
         }
         return respBuilder.build();
     }

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceHelper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceHelper.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceHelper.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceHelper.java
Thu Sep 29 07:59:04 2011
@@ -42,7 +42,7 @@ public class DomainServiceResourceHelper
         DomainObjectListReprBuilder builder = 
                 DomainObjectListReprBuilder.newBuilder(getResourceContext())
                     .usingLinkToBuilder(new DomainServiceLinkToBuilder())
-                    .withSelf(getSelfRef())
+                    .withSelf("services")
                     .withAdapters(serviceAdapters);
         
         return builder;

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceServerside.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceServerside.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceServerside.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainServiceResourceServerside.java
Thu Sep 29 07:59:04 2011
@@ -74,7 +74,7 @@ public class DomainServiceResourceServer
         AbstractReprBuilder<?> builder = 
                 DomainObjectReprBuilder.newBuilder(resourceContext)
                     .usingLinkToBuilder(new DomainServiceLinkToBuilder())
-                    .withAdapter(serviceAdapter);
+                    .with(serviceAdapter);
         
         return responseOfOk(RepresentationType.DOMAIN_OBJECT, Caching.ONE_DAY, builder).build();
     }

Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceHelper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceHelper.java?rev=1177197&r1=1177196&r2=1177197&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceHelper.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceHelper.java
Thu Sep 29 07:59:04 2011
@@ -34,7 +34,7 @@ public class UserResourceHelper extends 
     public UserReprBuilder user() {
         return UserReprBuilder.newBuilder(getResourceContext())
                     .withAuthenticationSession(getResourceContext().getAuthenticationSession())
-                    .withSelf(getSelfRef());
+                    .withSelf("user");
     }
 
 }



Mime
View raw message