You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by mf...@apache.org on 2014/07/03 18:46:03 UTC
[09/50] git commit: Added new pageTemplatesResource
Added new pageTemplatesResource
git-svn-id: https://svn.apache.org/repos/asf/rave/trunk@1530015 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/rave/repo
Commit: http://git-wip-us.apache.org/repos/asf/rave/commit/6bd9fc2c
Tree: http://git-wip-us.apache.org/repos/asf/rave/tree/6bd9fc2c
Diff: http://git-wip-us.apache.org/repos/asf/rave/diff/6bd9fc2c
Branch: refs/heads/angular
Commit: 6bd9fc2c81066229d876c51d69fc6a629f6aa6a5
Parents: 8285df3
Author: Matthew B. Franklin <mf...@apache.org>
Authored: Mon Oct 7 18:03:19 2013 +0000
Committer: Matthew B. Franklin <mf...@apache.org>
Committed: Mon Oct 7 18:03:19 2013 +0000
----------------------------------------------------------------------
.../apache/rave/rest/PageTemplatesResource.java | 66 ++++++++++++++
.../apache/rave/rest/model/PageTemplate.java | 91 ++++++++++++++++++++
.../rest/impl/DefaultPageTemplatesResource.java | 56 ++++++++++++
.../impl/DefaultPageTemplatesResourceTest.java | 86 ++++++++++++++++++
.../webapp/WEB-INF/cxf-applicationContext.xml | 1 +
5 files changed, 300 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/rave/blob/6bd9fc2c/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/PageTemplatesResource.java
----------------------------------------------------------------------
diff --git a/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/PageTemplatesResource.java b/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/PageTemplatesResource.java
new file mode 100644
index 0000000..6575c4c
--- /dev/null
+++ b/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/PageTemplatesResource.java
@@ -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);
+
+}
http://git-wip-us.apache.org/repos/asf/rave/blob/6bd9fc2c/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/PageTemplate.java
----------------------------------------------------------------------
diff --git a/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/PageTemplate.java b/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/PageTemplate.java
new file mode 100644
index 0000000..72b1383
--- /dev/null
+++ b/rave-components/rave-core-api/src/main/java/org/apache/rave/rest/model/PageTemplate.java
@@ -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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/rave/blob/6bd9fc2c/rave-components/rave-core/src/main/java/org/apache/rave/rest/impl/DefaultPageTemplatesResource.java
----------------------------------------------------------------------
diff --git a/rave-components/rave-core/src/main/java/org/apache/rave/rest/impl/DefaultPageTemplatesResource.java b/rave-components/rave-core/src/main/java/org/apache/rave/rest/impl/DefaultPageTemplatesResource.java
new file mode 100644
index 0000000..a91838e
--- /dev/null
+++ b/rave-components/rave-core/src/main/java/org/apache/rave/rest/impl/DefaultPageTemplatesResource.java
@@ -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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/rave/blob/6bd9fc2c/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/DefaultPageTemplatesResourceTest.java
----------------------------------------------------------------------
diff --git a/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/DefaultPageTemplatesResourceTest.java b/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/DefaultPageTemplatesResourceTest.java
new file mode 100644
index 0000000..ef1f2e0
--- /dev/null
+++ b/rave-components/rave-core/src/test/java/org/apache/rave/rest/impl/DefaultPageTemplatesResourceTest.java
@@ -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;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/rave/blob/6bd9fc2c/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml
----------------------------------------------------------------------
diff --git a/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml b/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml
index c5dbd9f..5afbdb6 100644
--- a/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml
+++ b/rave-portal-resources/src/main/webapp/WEB-INF/cxf-applicationContext.xml
@@ -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"/>