Author: mfranklin
Date: Mon Oct  7 18:03:19 2013
New Revision: 1530015

URL: http://svn.apache.org/r1530015
Log:
Added new pageTemplatesResource

Added:
    
rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/PageTemplatesResource.java
    
rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/PageTemplate.java
    
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/rest/impl/DefaultPageTemplatesResource.java
    rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/rest/
    
rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/
    
rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/DefaultPageTemplatesResourceTest.java
Modified:
    
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml

Added: 
rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/PageTemplatesResource.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/PageTemplatesResource.java?rev=1530015&view=auto
==============================================================================
--- 
rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/PageTemplatesResource.java
 (added)
+++ 
rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/PageTemplatesResource.java
 Mon Oct  7 18:03:19 2013
@@ -0,0 +1,66 @@
+/*
+ * 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.rave.rest;
+
+import org.apache.rave.rest.model.PageTemplate;
+import org.apache.rave.rest.model.SearchResult;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * Defines a resource for accessing PageTemplates
+ */
+@Path("/pageTemplates")
+public interface PageTemplatesResource {
+
+    /**
+     * Gets all page templates defined by the system
+     * @return a {@link SearchResult} with all templates
+     */
+    @GET
+    @Path("/")
+    @Produces(MediaType.APPLICATION_JSON)
+    SearchResult<PageTemplate> getAll();
+
+    /**
+     * Gets all page templates for the specified context
+     * @param context the context to get templates for
+     * @return a {@link SearchResult} with all templates in the context
+     */
+    @GET
+    @Path("/context/{context}")
+    @Produces(MediaType.APPLICATION_JSON)
+    SearchResult<PageTemplate> getAllForContext(@PathParam("context") String 
context);
+
+    /**
+     * Gets the specified page template by ID
+     * @param id the identifier of the page template
+     * @return a PageTemplate instance or null if none exists for that ID
+     */
+    @GET
+    @Path("/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    PageTemplate get(@PathParam("id") String id);
+
+}

Added: 
rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/PageTemplate.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/PageTemplate.java?rev=1530015&view=auto
==============================================================================
--- 
rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/PageTemplate.java
 (added)
+++ 
rave/trunk/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/PageTemplate.java
 Mon Oct  7 18:03:19 2013
@@ -0,0 +1,91 @@
+/*
+ * 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.rave.rest.model;
+
+/**
+ * REST model for PageTemplate objects
+ */
+public class PageTemplate implements RestEntity {
+
+    private String id;
+    private String name;
+    private String description;
+    private String pageType;
+    private String pageLayoutCode;
+    private boolean defaultTemplate;
+
+    public PageTemplate() {}
+
+    public PageTemplate(org.apache.rave.model.PageTemplate source) {
+        this.id = source.getId();
+        this.name = source.getName();
+        this.description = source.getDescription();
+        this.pageType = source.getPageType();
+        this.pageLayoutCode = source.getPageLayout().getCode();
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getPageType() {
+        return pageType;
+    }
+
+    public void setPageType(String pageType) {
+        this.pageType = pageType;
+    }
+
+    public String getPageLayoutCode() {
+        return pageLayoutCode;
+    }
+
+    public void setPageLayoutCode(String pageLayoutCode) {
+        this.pageLayoutCode = pageLayoutCode;
+    }
+
+    public boolean isDefaultTemplate() {
+        return defaultTemplate;
+    }
+
+    public void setDefaultTemplate(boolean defaultTemplate) {
+        this.defaultTemplate = defaultTemplate;
+    }
+}

Added: 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/rest/impl/DefaultPageTemplatesResource.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/rest/impl/DefaultPageTemplatesResource.java?rev=1530015&view=auto
==============================================================================
--- 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/rest/impl/DefaultPageTemplatesResource.java
 (added)
+++ 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/rest/impl/DefaultPageTemplatesResource.java
 Mon Oct  7 18:03:19 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.rave.rest.impl;
+
+import com.google.inject.Inject;
+import org.apache.rave.portal.repository.PageTemplateRepository;
+import org.apache.rave.rest.PageTemplatesResource;
+import org.apache.rave.rest.model.PageTemplate;
+import org.apache.rave.rest.model.SearchResult;
+
+import javax.ws.rs.PathParam;
+
+/**
+ * Default JAXRS implementation of teh {@link PageTemplatesResource}
+ */
+public class DefaultPageTemplatesResource implements PageTemplatesResource {
+
+    private PageTemplateRepository repository;
+
+    @Override
+    public SearchResult<PageTemplate> getAll() {
+        return null;
+    }
+
+    @Override
+    public SearchResult<PageTemplate> getAllForContext(@PathParam("context") 
String context) {
+        return null;
+    }
+
+    @Override
+    public PageTemplate get(@PathParam("id") String id) {
+        return null;
+    }
+
+    @Inject
+    public void setRepository(PageTemplateRepository repository) {
+        this.repository = repository;
+    }
+}

Added: 
rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/DefaultPageTemplatesResourceTest.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/DefaultPageTemplatesResourceTest.java?rev=1530015&view=auto
==============================================================================
--- 
rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/DefaultPageTemplatesResourceTest.java
 (added)
+++ 
rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/DefaultPageTemplatesResourceTest.java
 Mon Oct  7 18:03:19 2013
@@ -0,0 +1,86 @@
+/*
+ * 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.rave.rest.impl;
+
+
+import com.google.common.collect.Lists;
+import org.apache.rave.model.PageTemplate;
+import org.apache.rave.portal.model.impl.PageTemplateImpl;
+import org.apache.rave.portal.repository.PageTemplateRepository;
+import org.apache.rave.rest.PageTemplatesResource;
+import org.apache.rave.rest.model.SearchResult;
+import org.junit.Before;
+
+import java.util.List;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class DefaultPageTemplatesResourceTest {
+
+    private PageTemplatesResource resource;
+    private PageTemplateRepository repository;
+
+    @Before
+    public void setup() {
+        resource = new DefaultPageTemplatesResource();
+        repository = createMock(PageTemplateRepository.class);
+        ((DefaultPageTemplatesResource)resource).setRepository(repository);
+    }
+
+    public void getAll() {
+        int count = 4;
+        List<PageTemplate> answer = getRepositoryTemplates(count);
+        expect(repository.getAll()).andReturn(answer);
+        replay(repository);
+
+        SearchResult< org.apache.rave.rest.model.PageTemplate> result = 
resource.getAll();
+        assertThat(result.getNumberOfPages(), is(equalTo(1)));
+        assertThat(result.getCurrentPage(), is(equalTo(0)));
+        assertThat(result.getTotalResults(), is(equalTo(1)));
+    }
+
+    public void getAllForContext() {
+        int count = 4;
+        String context = "context";
+        List<PageTemplate> answer = getRepositoryTemplates(count);
+        expect(repository.getAllForType(context)).andReturn(answer);
+        replay(repository);
+
+        SearchResult< org.apache.rave.rest.model.PageTemplate> result = 
resource.getAllForContext(context);
+        assertThat(result.getNumberOfPages(), is(equalTo(1)));
+        assertThat(result.getCurrentPage(), is(equalTo(0)));
+        assertThat(result.getTotalResults(), is(equalTo(1)));
+    }
+
+    private List<PageTemplate> getRepositoryTemplates(int i) {
+        List<PageTemplate> templates = Lists.newArrayList();
+        for(int j=0; j<i; j++) {
+            templates.add(new PageTemplateImpl());
+        }
+        return templates;
+    }
+
+
+}

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml?rev=1530015&r1=1530014&r2=1530015&view=diff
==============================================================================
--- 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml
 (original)
+++ 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml
 Mon Oct  7 18:03:19 2013
@@ -83,6 +83,7 @@
     <bean id="regionWidgetsBean" 
class="org.apache.rave.rest.impl.DefaultRegionWidgetsResource" 
autowire="byType" />
     <bean id="pageUsersResource" 
class="org.apache.rave.rest.impl.DefaultPageUsersResource" autowire="byType" />
     <bean id="pagesForRenderBean" 
class="org.apache.rave.rest.impl.DefaultPageForRenderResource" 
autowire="byType" />
+    <bean id="pageTemplatesBean" 
class="org.apache.rave.rest.impl.DefaultPageTemplatesResource" 
autowire="byType" />
 
     <bean id="JsonWrapperResponseFilter" 
class="org.apache.rave.rest.filters.JsonWrapperResponseFilter"/>
     <bean id="CreatedResponseFilter" 
class="org.apache.rave.rest.filters.CreatedResponseFilter"/>


Reply via email to