This is an automated email from the ASF dual-hosted git repository. cziegeler pushed a commit to branch appmod/java-upgrade-20250910060318 in repository https://gitbox.apache.org/repos/asf/sling-samples.git
commit 755f8e1e929af69f6bac1da754fe2ae3fbdcacea Author: Carsten Ziegeler <[email protected]> AuthorDate: Wed Sep 10 08:53:36 2025 +0200 Applied Spotless code formatting --- slingshot/pom.xml | 240 ++++++++++----------- .../sling/sample/slingshot/SlingshotConstants.java | 27 +-- .../sling/sample/slingshot/SlingshotUtil.java | 38 ++-- .../sling/sample/slingshot/comments/Comment.java | 27 +-- .../sample/slingshot/comments/CommentsService.java | 29 +-- .../sample/slingshot/comments/CommentsUtil.java | 27 +-- .../comments/impl/CommentPostServlet.java | 59 ++--- .../comments/impl/CommentsServiceImpl.java | 54 ++--- .../sample/slingshot/impl/InternalConstants.java | 28 +-- .../sling/sample/slingshot/impl/SetupService.java | 54 ++--- .../apache/sling/sample/slingshot/impl/Util.java | 37 ++-- .../sample/slingshot/model/PropertiesSupport.java | 5 +- .../sling/sample/slingshot/model/Stream.java | 2 +- .../sling/sample/slingshot/model/StreamEntry.java | 10 +- .../sling/sample/slingshot/model/StreamInfo.java | 38 ++-- .../apache/sling/sample/slingshot/model/User.java | 28 +-- .../sling/sample/slingshot/model/UserInfo.java | 30 +-- .../sling/sample/slingshot/model/package-info.java | 2 - .../sample/slingshot/ratings/RatingsService.java | 30 +-- .../sample/slingshot/ratings/RatingsUtil.java | 27 +-- .../slingshot/ratings/impl/RatingPostServlet.java | 58 ++--- .../slingshot/ratings/impl/RatingsServiceImpl.java | 50 ++--- .../sling/sample/slingshot/SlingshotUtilTest.java | 34 +-- .../sample/slingshot/impl/SetupServiceTest.java | 60 +++--- .../sling/sample/slingshot/impl/UtilTest.java | 55 ++--- .../ratings/impl/RatingPostServletTest.java | 40 ++-- .../ratings/impl/RatingServiceImplTest.java | 41 ++-- 27 files changed, 576 insertions(+), 554 deletions(-) diff --git a/slingshot/pom.xml b/slingshot/pom.xml index 18686e1..15603af 100644 --- a/slingshot/pom.xml +++ b/slingshot/pom.xml @@ -32,121 +32,22 @@ <name>Apache Sling Sample Slingshot</name> - <!-- Properties --> - <properties> - <sling.java.version>17</sling.java.version> - <maven.compiler.source>17</maven.compiler.source> - <maven.compiler.target>17</maven.compiler.target> - <maven.compiler.release>17</maven.compiler.release> - <!-- If you set this to true, the scripts are mounted through the file resource provider! --> - <fileMount>false</fileMount> - </properties> - <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-samples.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-samples.git</developerConnection> + <tag>HEAD</tag> <url>https://gitbox.apache.org/repos/asf?p=sling-samples.git</url> - <tag>HEAD</tag> - </scm> - - <build> - <plugins> - <!-- Bundling the sample project --> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-baseline-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.sling</groupId> - <artifactId>slingstart-maven-plugin</artifactId> - <extensions>true</extensions> - <executions> - <execution> - <id>attach-prov-model</id> - <goals> - <goal>attach-slingfeature</goal> - <goal>attach-modelarchive</goal> - </goals> - </execution> - </executions> - <configuration> - <setFeatureVersions>true</setFeatureVersions> - <attach> - <type>jar</type> - </attach> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <configuration> - <excludes> - <exclude>src/main/resources/SLING-INF/content/**/*.json</exclude> - <exclude>src/main/resources/SLING-INF/content/slingshot/resources/css/*.css</exclude> - <exclude>src/main/resources/SLING-INF/content/slingshot/resources/js/*.js</exclude> - <exclude>src/main/resources/SLING-INF/content/slingshot/resources/fonts/*.svg</exclude> - <exclude>src/test/resources/**.json</exclude> - <exclude>**/*.woff2</exclude> - </excludes> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <!-- - <configuration> - <testSourceDirectory>src/main/it</testSourceDirectory> - </configuration> - --> - <executions> - <execution> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - - </build> + </scm> - <profiles> - <profile> - <!-- - Use this profile to install the OSGi bundle - automatically, during development - --> - <id>autoInstallBundle</id> - <activation> - <activeByDefault>false</activeByDefault> - </activation> - <build> - <plugins> - <plugin> - <groupId>org.apache.sling</groupId> - <artifactId>maven-sling-plugin</artifactId> - <executions> - <execution> - <id>install-bundle</id> - <goals> - <goal>validate</goal> - <goal>install</goal> - </goals> - <configuration> - <mountByFS>${fileMount}</mountByFS> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> + <!-- Properties --> + <properties> + <sling.java.version>17</sling.java.version> + <maven.compiler.source>17</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.release>17</maven.compiler.release> + <!-- If you set this to true, the scripts are mounted through the file resource provider! --> + <fileMount>false</fileMount> + </properties> <dependencies> <!-- OSGi --> @@ -196,16 +97,16 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>javax.jcr</groupId> - <artifactId>jcr</artifactId> - <scope>provided</scope> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + <scope>provided</scope> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <scope>provided</scope> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <scope>provided</scope> </dependency> - + <!-- test dependencies --> <dependency> <groupId>org.hamcrest</groupId> @@ -243,9 +144,108 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <scope>test</scope> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <scope>test</scope> </dependency> </dependencies> + + <build> + <plugins> + <!-- Bundling the sample project --> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-baseline-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.sling</groupId> + <artifactId>slingstart-maven-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <setFeatureVersions>true</setFeatureVersions> + <attach> + <type>jar</type> + </attach> + </configuration> + <executions> + <execution> + <id>attach-prov-model</id> + <goals> + <goal>attach-slingfeature</goal> + <goal>attach-modelarchive</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-plugin</artifactId> + <configuration> + <excludes> + <exclude>src/main/resources/SLING-INF/content/**/*.json</exclude> + <exclude>src/main/resources/SLING-INF/content/slingshot/resources/css/*.css</exclude> + <exclude>src/main/resources/SLING-INF/content/slingshot/resources/js/*.js</exclude> + <exclude>src/main/resources/SLING-INF/content/slingshot/resources/fonts/*.svg</exclude> + <exclude>src/test/resources/**.json</exclude> + <exclude>**/*.woff2</exclude> + </excludes> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <!-- + <configuration> + <testSourceDirectory>src/main/it</testSourceDirectory> + </configuration> + --> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + + </build> + + <profiles> + <profile> + <!-- + Use this profile to install the OSGi bundle + automatically, during development + --> + <id>autoInstallBundle</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.sling</groupId> + <artifactId>maven-sling-plugin</artifactId> + <executions> + <execution> + <id>install-bundle</id> + <goals> + <goal>validate</goal> + <goal>install</goal> + </goals> + <configuration> + <mountByFS>${fileMount}</mountByFS> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> </project> diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotConstants.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotConstants.java index 11edd2a..ababab9 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotConstants.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotConstants.java @@ -1,22 +1,23 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot; - public abstract class SlingshotConstants { /** This is the resource path for the root of our application. */ diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotUtil.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotUtil.java index 2ae1718..f3802f1 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotUtil.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotUtil.java @@ -1,18 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot; @@ -30,11 +32,11 @@ public abstract class SlingshotUtil { final String prefix = SlingshotConstants.APP_ROOT_PATH + "/"; String id = null; - if ( resource.getPath().startsWith(prefix) ) { + if (resource.getPath().startsWith(prefix)) { final int areaEnd = resource.getPath().indexOf('/', prefix.length()); - if ( areaEnd != -1 ) { + if (areaEnd != -1) { final int userEnd = resource.getPath().indexOf('/', areaEnd + 1); - if ( userEnd == -1 ) { + if (userEnd == -1) { id = resource.getPath().substring(areaEnd + 1); } else { id = resource.getPath().substring(areaEnd + 1, userEnd); @@ -53,7 +55,7 @@ public abstract class SlingshotUtil { final String prefix = SlingshotConstants.APP_ROOT_PATH + "/users/" + getUserId(resource) + "/"; final String path = resource.getPath(); - if ( path != null && path.startsWith(prefix) ) { + if (path != null && path.startsWith(prefix)) { return path.substring(prefix.length() - 1); } return null; @@ -65,8 +67,8 @@ public abstract class SlingshotUtil { * @return {@code true} if it is a known user. */ public static boolean isUser(final SlingHttpServletRequest request) { - final boolean isUser = request.getRemoteUser() != null && !request.getRemoteUser().equals("anonymous"); + final boolean isUser = + request.getRemoteUser() != null && !request.getRemoteUser().equals("anonymous"); return isUser; } - } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java index 383590c..b4ae20d 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java @@ -1,18 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.comments; @@ -59,5 +61,4 @@ public class Comment { public void setCreatedBy(final String createdBy) { this.createdBy = createdBy; } - } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsService.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsService.java index e9c1a15..aa18174 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsService.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsService.java @@ -1,18 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.comments; @@ -39,6 +41,5 @@ public interface CommentsService { * @param c The commoent * @throws PersistenceException If the comment can't be added */ - void addComment(final Resource resource, final Comment c) - throws PersistenceException; + void addComment(final Resource resource, final Comment c) throws PersistenceException; } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java index 049f7dc..d5a6ff3 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java @@ -1,22 +1,23 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.comments; - public abstract class CommentsUtil { /** The resource type for a comment. */ diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentPostServlet.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentPostServlet.java index 1a9dded..9df7b11 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentPostServlet.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentPostServlet.java @@ -1,27 +1,29 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.comments.impl; -import java.io.IOException; -import java.io.Serial; - import javax.servlet.Servlet; import javax.servlet.ServletException; +import java.io.IOException; +import java.io.Serial; + import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.LoginException; @@ -38,12 +40,13 @@ import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Component(service = Servlet.class, - property={ - "sling.servlet.methods=POST", - "sling.servlet.extensions=comments", - "sling.servlet.resourceTypes=" + StreamEntry.RESOURCETYPE - }) +@Component( + service = Servlet.class, + property = { + "sling.servlet.methods=POST", + "sling.servlet.extensions=comments", + "sling.servlet.resourceTypes=" + StreamEntry.RESOURCETYPE + }) public class CommentPostServlet extends SlingAllMethodsServlet { @Serial @@ -58,9 +61,8 @@ public class CommentPostServlet extends SlingAllMethodsServlet { private CommentsService commentsService; @Override - protected void doPost(final SlingHttpServletRequest request, - final SlingHttpServletResponse response) - throws ServletException, IOException { + protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) + throws ServletException, IOException { final String title = request.getParameter(CommentsUtil.PROPERTY_TITLE); final String text = request.getParameter(CommentsUtil.PROPERTY_TEXT); @@ -74,7 +76,8 @@ public class CommentPostServlet extends SlingAllMethodsServlet { try { resolver = factory.getServiceResourceResolver(null); - final Resource reqResource = resolver.getResource(request.getResource().getPath()); + final Resource reqResource = + resolver.getResource(request.getResource().getPath()); final Comment c = new Comment(); c.setTitle(title); @@ -83,18 +86,16 @@ public class CommentPostServlet extends SlingAllMethodsServlet { this.commentsService.addComment(reqResource, c); - // send redirect at the end final String path = request.getResource().getPath(); response.sendRedirect(resolver.map(request.getContextPath() + path + ".html")); - } catch ( final LoginException le ) { + } catch (final LoginException le) { throw new ServletException("Unable to login", le); } finally { - if ( resolver != null ) { + if (resolver != null) { resolver.close(); } } } - } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentsServiceImpl.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentsServiceImpl.java index 9525ba5..99d667a 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentsServiceImpl.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentsServiceImpl.java @@ -1,27 +1,29 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.comments.impl; -import java.util.HashMap; -import java.util.Map; - import javax.jcr.Node; import javax.jcr.RepositoryException; +import java.util.HashMap; +import java.util.Map; + import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; @@ -53,7 +55,7 @@ public class CommentsServiceImpl implements CommentsService { @Override public String getCommentsResourcePath(final Resource resource) { final String contentPath = SlingshotUtil.getContentPath(resource); - if ( contentPath != null ) { + if (contentPath != null) { final String fullPath = SlingshotConstants.APP_ROOT_PATH + "/users/" + SlingshotUtil.getUserId(resource) + "/ugc/comments" + contentPath; @@ -66,13 +68,12 @@ public class CommentsServiceImpl implements CommentsService { * @see org.apache.sling.sample.slingshot.comments.CommentsService#addComment(org.apache.sling.api.resource.Resource, org.apache.sling.sample.slingshot.comments.Comment) */ @Override - public void addComment(final Resource resource, final Comment c) - throws PersistenceException { + public void addComment(final Resource resource, final Comment c) throws PersistenceException { final String commentsPath = this.getCommentsResourcePath(resource); final Map<String, Object> props = new HashMap<String, Object>(); props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, RESOURCETYPE_COMMENTS); - final Resource ratingsResource = ResourceUtil.getOrCreateResource(resource.getResourceResolver(), - commentsPath, props, null, true); + final Resource ratingsResource = + ResourceUtil.getOrCreateResource(resource.getResourceResolver(), commentsPath, props, null, true); final Map<String, Object> properties = new HashMap<String, Object>(); properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, CommentsUtil.RESOURCETYPE_COMMENT); @@ -83,7 +84,7 @@ public class CommentsServiceImpl implements CommentsService { // we try it five times PersistenceException exception = null; Resource newResource = null; - for(int i=0; i<5; i++) { + for (int i = 0; i < 5; i++) { try { exception = null; final String name = ResourceUtil.createUniqueChildName(ratingsResource, Util.filter(c.getTitle())); @@ -91,29 +92,28 @@ public class CommentsServiceImpl implements CommentsService { resource.getResourceResolver().commit(); break; - } catch ( final PersistenceException pe) { + } catch (final PersistenceException pe) { resource.getResourceResolver().revert(); resource.getResourceResolver().refresh(); exception = pe; } } - if ( exception != null ) { + if (exception != null) { throw exception; } // order node at the top (if jcr based) final Node newNode = newResource.adaptTo(Node.class); - if ( newNode != null ) { + if (newNode != null) { try { final Node parent = newNode.getParent(); final Node firstNode = parent.getNodes().nextNode(); - if ( !firstNode.getName().equals(newNode.getName()) ) { + if (!firstNode.getName().equals(newNode.getName())) { parent.orderBefore(newNode.getName(), firstNode.getName()); newNode.getSession().save(); } - } catch ( final RepositoryException re) { + } catch (final RepositoryException re) { logger.error("Unable to order comment to the top", re); } } } - } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java index 4525bb3..bac7d57 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java @@ -1,22 +1,23 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.impl; - public abstract class InternalConstants { /** This is name of the service user. */ @@ -24,5 +25,4 @@ public abstract class InternalConstants { /** The resource type for the root of slingshot. */ public static final String RESOURCETYPE_HOME = "slingshot/Home"; - } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/SetupService.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/SetupService.java index af79085..6f6a28d 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/SetupService.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/SetupService.java @@ -1,27 +1,29 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.impl; +import javax.jcr.RepositoryException; + import java.io.IOException; import java.util.HashMap; import java.util.Map; -import javax.jcr.RepositoryException; - import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.ModifiableValueMap; import org.apache.sling.api.resource.PersistenceException; @@ -51,20 +53,18 @@ public class SetupService { private static final String[] USERS = new String[] {"slingshot1", "slingshot2"}; - private static final String[] FOLDERS = new String[] { - "info", - "settings", - "ugc"}; + private static final String[] FOLDERS = new String[] {"info", "settings", "ugc"}; @Activate - protected void activate(final BundleContext bc) throws IOException, LoginException, PersistenceException, RepositoryException { + protected void activate(final BundleContext bc) + throws IOException, LoginException, PersistenceException, RepositoryException { logger.info("Setting up SlingShot..."); ResourceResolver resolver = null; try { resolver = this.factory.getServiceResourceResolver(null); setupContent(resolver); } finally { - if ( resolver != null ) { + if (resolver != null) { resolver.close(); } } @@ -73,27 +73,27 @@ public class SetupService { private void setupContent(final ResourceResolver resolver) throws PersistenceException { final Resource root = resolver.getResource(SlingshotConstants.APP_ROOT_PATH); - if ( root != null ) { + if (root != null) { // fix resource type of root folder - if ( !root.isResourceType(InternalConstants.RESOURCETYPE_HOME)) { + if (!root.isResourceType(InternalConstants.RESOURCETYPE_HOME)) { final ModifiableValueMap mvm = root.adaptTo(ModifiableValueMap.class); mvm.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, InternalConstants.RESOURCETYPE_HOME); resolver.commit(); } final Resource usersResource = root.getChild("users"); - for(final String userName : USERS) { + for (final String userName : USERS) { Resource homeResource = resolver.getResource(usersResource, userName); - if ( homeResource == null ) { + if (homeResource == null) { final Map<String, Object> props = new HashMap<String, Object>(); props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, User.RESOURCETYPE); homeResource = resolver.create(usersResource, userName, props); resolver.commit(); } - for(final String def : FOLDERS) { + for (final String def : FOLDERS) { final int index = def.indexOf(':'); final String name; final String rt; - if ( index == -1 ) { + if (index == -1) { name = def; rt = "sling:OrderedFolder"; } else { @@ -101,7 +101,7 @@ public class SetupService { rt = def.substring(index + 1); } final Resource rsrc = resolver.getResource(homeResource, name); - if ( rsrc == null ) { + if (rsrc == null) { final Map<String, Object> props = new HashMap<String, Object>(); props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, rt); resolver.create(homeResource, name, props); diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/Util.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/Util.java index 4672f6e..14d5698 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/Util.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/Util.java @@ -1,33 +1,34 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.impl; - public abstract class Util { private static final String ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789_"; private static final char REPLACEMENT_CHAR = '_'; public static String filter(final String rsrcname) { - final StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); char lastAdded = 0; final String name = rsrcname.toLowerCase(); - for(int i=0; i < name.length(); i++) { + for (int i = 0; i < name.length(); i++) { final char c = name.charAt(i); char toAdd = c; @@ -38,7 +39,7 @@ public abstract class Util { } toAdd = REPLACEMENT_CHAR; - } else if(i == 0 && Character.isDigit(c)) { + } else if (i == 0 && Character.isDigit(c)) { sb.append(REPLACEMENT_CHAR); } @@ -46,12 +47,10 @@ public abstract class Util { lastAdded = toAdd; } - if (sb.length()==0) { + if (sb.length() == 0) { sb.append(REPLACEMENT_CHAR); } return sb.toString(); } - - } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/PropertiesSupport.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/PropertiesSupport.java index e6da85c..9cc2db3 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/PropertiesSupport.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/PropertiesSupport.java @@ -33,8 +33,8 @@ public abstract class PropertiesSupport { } protected ValueMap getProperties() { - if ( this.properties == null ) { - if ( this.resource == null ) { + if (this.properties == null) { + if (this.resource == null) { this.properties = ResourceUtil.getValueMap(null); } else { this.properties = resource.getValueMap(); @@ -42,5 +42,4 @@ public abstract class PropertiesSupport { } return this.properties; } - } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/Stream.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/Stream.java index fdb8254..b1b6fea 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/Stream.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/Stream.java @@ -34,7 +34,7 @@ public class Stream { } public StreamInfo getInfo() { - if ( info == null ) { + if (info == null) { info = new StreamInfo(this.resource == null ? null : this.resource.getChild("info")); } return info; diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/StreamEntry.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/StreamEntry.java index 7423f2f..adc01ff 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/StreamEntry.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/StreamEntry.java @@ -41,8 +41,8 @@ public class StreamEntry extends PropertiesSupport { public String getTitle() { String value = this.getProperties().get(PROPERTY_TITLE, String.class); - if ( value == null ) { - if ( resource != null ) { + if (value == null) { + if (resource != null) { value = resource.getName(); } else { value = "No Title"; @@ -57,12 +57,12 @@ public class StreamEntry extends PropertiesSupport { } public Stream getStream() { - if ( this.stream == null ) { - if ( resource == null ) { + if (this.stream == null) { + if (resource == null) { stream = new Stream(null); } else { Resource rsrc = this.resource.getParent(); - while (rsrc != null && !rsrc.isResourceType(Stream.RESOURCETYPE) ) { + while (rsrc != null && !rsrc.isResourceType(Stream.RESOURCETYPE)) { rsrc = rsrc.getParent(); } stream = new Stream(rsrc); diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/StreamInfo.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/StreamInfo.java index f70e625..a71b09c 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/StreamInfo.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/StreamInfo.java @@ -1,18 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.model; @@ -37,8 +39,8 @@ public class StreamInfo extends PropertiesSupport { public String getTitle() { String value = this.getProperties().get(PROPERTY_TITLE, String.class); - if ( value == null ) { - if ( resource != null ) { + if (value == null) { + if (resource != null) { value = resource.getParent().getName(); } else { value = "No Title"; @@ -53,11 +55,11 @@ public class StreamInfo extends PropertiesSupport { } public long getEntryCount() { - if ( entryCount == -1 ) { + if (entryCount == -1) { entryCount = 0; - if ( this.resource != null ) { - for(final Resource rsrc : this.resource.getParent().getChildren()) { - if ( rsrc.isResourceType(StreamEntry.RESOURCETYPE) ) { + if (this.resource != null) { + for (final Resource rsrc : this.resource.getParent().getChildren()) { + if (rsrc.isResourceType(StreamEntry.RESOURCETYPE)) { entryCount++; } } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/User.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/User.java index b4a5027..2e75b71 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/User.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/User.java @@ -1,18 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.model; @@ -32,7 +34,7 @@ public class User { } public UserInfo getInfo() { - if ( info == null ) { + if (info == null) { info = new UserInfo(this.resource.getChild("info")); } return info; diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/UserInfo.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/UserInfo.java index 200fc20..fd9498c 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/UserInfo.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/UserInfo.java @@ -1,18 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.model; @@ -35,8 +37,8 @@ public class UserInfo extends PropertiesSupport { public String getName() { String value = this.getProperties().get(PROPERTY_NAME, String.class); - if ( value == null ) { - if ( resource != null ) { + if (value == null) { + if (resource != null) { value = resource.getParent().getName(); } else { value = "No Title"; diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/package-info.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/package-info.java index d087584..57660d3 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/package-info.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/model/package-info.java @@ -18,5 +18,3 @@ */ @org.osgi.annotation.versioning.Version("1.0") package org.apache.sling.sample.slingshot.model; - - diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java index 25f9753..5555c97 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java @@ -1,18 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.ratings; @@ -33,7 +35,6 @@ public interface RatingsService { */ String getRatingsResourcePath(Resource resource); - /** * Get the overall rating for a resource. * @param resource The content resource, this is usually an entry. @@ -61,6 +62,5 @@ public interface RatingsService { * the passed in content resource is not part of * Slingshot. */ - void setRating(Resource resource, String userId, double rating) - throws PersistenceException; + void setRating(Resource resource, String userId, double rating) throws PersistenceException; } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java index 364a4cc..9714b76 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java @@ -1,22 +1,23 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.ratings; - /** * Utility class for handling ratings. */ diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServlet.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServlet.java index 25d95e2..1aced6e 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServlet.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServlet.java @@ -1,28 +1,30 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.ratings.impl; +import javax.servlet.Servlet; +import javax.servlet.ServletException; + import java.io.IOException; import java.io.PrintWriter; import java.io.Serial; -import javax.servlet.Servlet; -import javax.servlet.ServletException; - import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.LoginException; @@ -42,12 +44,13 @@ import org.slf4j.LoggerFactory; * The ratings post servlet is registered for a POST to an entry with * the selector "rating". */ -@Component(service = Servlet.class, -property={ - "sling.servlet.methods=POST", - "sling.servlet.extensions=ratings", - "sling.servlet.resourceTypes=" + StreamEntry.RESOURCETYPE -}) +@Component( + service = Servlet.class, + property = { + "sling.servlet.methods=POST", + "sling.servlet.extensions=ratings", + "sling.servlet.resourceTypes=" + StreamEntry.RESOURCETYPE + }) public class RatingPostServlet extends SlingAllMethodsServlet { @Serial @@ -62,9 +65,8 @@ public class RatingPostServlet extends SlingAllMethodsServlet { private RatingsService ratingsService; @Override - protected void doPost(final SlingHttpServletRequest request, - final SlingHttpServletResponse response) - throws ServletException, IOException { + protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) + throws ServletException, IOException { final String rating = request.getParameter(RatingsUtil.PROPERTY_RATING); final String userId = request.getRemoteUser(); @@ -75,14 +77,15 @@ public class RatingPostServlet extends SlingAllMethodsServlet { try { resolver = factory.getServiceResourceResolver(null); - final Resource reqResource = resolver.getResource(request.getResource().getPath()); + final Resource reqResource = + resolver.getResource(request.getResource().getPath()); ratingsService.setRating(reqResource, userId, Double.valueOf(rating)); - } catch ( final LoginException le ) { + } catch (final LoginException le) { throw new ServletException("Unable to login", le); } finally { - if ( resolver != null ) { + if (resolver != null) { resolver.close(); } } @@ -97,5 +100,4 @@ public class RatingPostServlet extends SlingAllMethodsServlet { pw.print(String.valueOf(ratingsService.getRating(request.getResource()))); pw.print("}"); } - } diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java index 054b91c..a3a2f94 100644 --- a/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java +++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java @@ -1,18 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.ratings.impl; @@ -34,7 +36,7 @@ import org.osgi.service.component.annotations.Component; /** * Implementation of the ratings service */ -@Component(service=RatingsService.class) +@Component(service = RatingsService.class) public class RatingsServiceImpl implements RatingsService { /** The resource type for the rating holder. */ @@ -46,7 +48,7 @@ public class RatingsServiceImpl implements RatingsService { @Override public String getRatingsResourcePath(final Resource resource) { final String contentPath = SlingshotUtil.getContentPath(resource); - if ( contentPath != null ) { + if (contentPath != null) { final String fullPath = SlingshotConstants.APP_ROOT_PATH + "/users/" + SlingshotUtil.getUserId(resource) + "/ugc/ratings" + contentPath; @@ -62,17 +64,17 @@ public class RatingsServiceImpl implements RatingsService { public double getRating(final Resource resource) { final String fullPath = getRatingsResourcePath(resource); float rating = 0; - if ( fullPath != null ) { + if (fullPath != null) { final Resource ratingsResource = resource.getChild(fullPath); - if ( ratingsResource != null ) { + if (ratingsResource != null) { int count = 0; - for(final Resource r : ratingsResource.getChildren()) { + for (final Resource r : ratingsResource.getChildren()) { final ValueMap vm = r.getValueMap(); final double current = vm.get(RatingsUtil.PROPERTY_RATING, 0.0); rating += current; count++; } - if ( count > 0 ) { + if (count > 0) { rating = rating / count; } } @@ -89,7 +91,7 @@ public class RatingsServiceImpl implements RatingsService { double rating = 0; final Resource r = resource.getResourceResolver().getResource(fullPath + "/" + userId); - if ( r != null ) { + if (r != null) { final ValueMap vm = r.getValueMap(); rating = vm.get(RatingsUtil.PROPERTY_RATING, 0.0); } @@ -101,16 +103,16 @@ public class RatingsServiceImpl implements RatingsService { */ @Override public void setRating(final Resource resource, final String userId, final double rating) - throws PersistenceException { - final String ratingsPath = getRatingsResourcePath(resource) ; + throws PersistenceException { + final String ratingsPath = getRatingsResourcePath(resource); final Map<String, Object> props = new HashMap<String, Object>(); props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, RESOURCETYPE_RATINGS); - final Resource ratingsResource = ResourceUtil.getOrCreateResource(resource.getResourceResolver(), - ratingsPath, props, null, true); + final Resource ratingsResource = + ResourceUtil.getOrCreateResource(resource.getResourceResolver(), ratingsPath, props, null, true); final Resource ratingRsrc = resource.getResourceResolver().getResource(ratingsResource, userId); - if ( ratingRsrc == null ) { + if (ratingRsrc == null) { props.clear(); props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, RatingsUtil.RESOURCETYPE_RATING); props.put(RatingsUtil.PROPERTY_RATING, String.valueOf(rating)); diff --git a/slingshot/src/test/java/org/apache/sling/sample/slingshot/SlingshotUtilTest.java b/slingshot/src/test/java/org/apache/sling/sample/slingshot/SlingshotUtilTest.java index 3c3bd4e..b5a7f57 100644 --- a/slingshot/src/test/java/org/apache/sling/sample/slingshot/SlingshotUtilTest.java +++ b/slingshot/src/test/java/org/apache/sling/sample/slingshot/SlingshotUtilTest.java @@ -1,31 +1,33 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - import org.apache.sling.api.resource.Resource; import org.apache.sling.testing.mock.sling.junit.SlingContext; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + public class SlingshotUtilTest { @Rule diff --git a/slingshot/src/test/java/org/apache/sling/sample/slingshot/impl/SetupServiceTest.java b/slingshot/src/test/java/org/apache/sling/sample/slingshot/impl/SetupServiceTest.java index 84f29e9..0953fbe 100644 --- a/slingshot/src/test/java/org/apache/sling/sample/slingshot/impl/SetupServiceTest.java +++ b/slingshot/src/test/java/org/apache/sling/sample/slingshot/impl/SetupServiceTest.java @@ -1,31 +1,23 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.impl; -import static org.apache.sling.sample.slingshot.impl.InternalConstants.RESOURCETYPE_HOME; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import javax.jcr.Session; import javax.jcr.SimpleCredentials; @@ -40,20 +32,30 @@ import org.junit.Rule; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; +import static org.apache.sling.sample.slingshot.impl.InternalConstants.RESOURCETYPE_HOME; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class SetupServiceTest { @Rule public SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK); - // @Test - public void setup() throws Exception{ + // @Test + public void setup() throws Exception { // create expected content structure context.load().json("/slingshot.json", SlingshotConstants.APP_ROOT_PATH); // create a dummy config admin to prevent registration of service user amendments ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class); - when(configAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] { null }); + when(configAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] {null}); context.registerService(ConfigurationAdmin.class, configAdmin); // run the activation code @@ -62,7 +64,7 @@ public class SetupServiceTest { // validate that the expected users are created Session adminSession = context.resourceResolver().adaptTo(Session.class); UserManager userManager = AccessControlUtil.getUserManager(adminSession); - for ( String user : new String[] { "slingshot1", "slingshot2", InternalConstants.SERVICE_USER_NAME } ) { + for (String user : new String[] {"slingshot1", "slingshot2", InternalConstants.SERVICE_USER_NAME}) { assertThat(userManager.getAuthorizable(user), notNullValue()); } @@ -80,7 +82,9 @@ public class SetupServiceTest { Session user = adminSession.impersonate(new SimpleCredentials("slingshot1", "slingshot1".toCharArray())); - assertThat(user.hasPermission(SlingshotConstants.APP_ROOT_PATH+"/users/slingshot1/info", "read,add_node,set_property"), equalTo(true)); + assertThat( + user.hasPermission( + SlingshotConstants.APP_ROOT_PATH + "/users/slingshot1/info", "read,add_node,set_property"), + equalTo(true)); } - } diff --git a/slingshot/src/test/java/org/apache/sling/sample/slingshot/impl/UtilTest.java b/slingshot/src/test/java/org/apache/sling/sample/slingshot/impl/UtilTest.java index f366119..f2433b5 100644 --- a/slingshot/src/test/java/org/apache/sling/sample/slingshot/impl/UtilTest.java +++ b/slingshot/src/test/java/org/apache/sling/sample/slingshot/impl/UtilTest.java @@ -1,24 +1,23 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.impl; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; - import java.util.Arrays; import java.util.Collection; @@ -27,32 +26,34 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + @RunWith(Parameterized.class) public class UtilTest { - + @Parameters public static Collection<Object[]> data() { - return Arrays.asList(new Object[][] { - {"valid_name", "valid_name"}, - {"hyphen-included", "hyphen_included"}, - {"multiple---replacements", "multiple_replacements"}, - {"MixedCase", "mixedcase"}, - {"0leadingdigit", "_0leadingdigit"} - }); + return Arrays.asList(new Object[][] { + {"valid_name", "valid_name"}, + {"hyphen-included", "hyphen_included"}, + {"multiple---replacements", "multiple_replacements"}, + {"MixedCase", "mixedcase"}, + {"0leadingdigit", "_0leadingdigit"} + }); } private final String input; private final String output; - + public UtilTest(String input, String output) { this.input = input; this.output = output; } - + @Test public void filter() { - + assertThat(output, equalTo(Util.filter(input))); } - } diff --git a/slingshot/src/test/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServletTest.java b/slingshot/src/test/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServletTest.java index e2a99de..980d193 100644 --- a/slingshot/src/test/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServletTest.java +++ b/slingshot/src/test/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServletTest.java @@ -1,25 +1,23 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.ratings.impl; -import static javax.servlet.http.HttpServletResponse.SC_OK; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; - import java.util.HashMap; import java.util.Map; @@ -33,12 +31,16 @@ import org.hamcrest.Matchers; import org.junit.Rule; import org.mockito.Mockito; +import static javax.servlet.http.HttpServletResponse.SC_OK; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + public class RatingPostServletTest { @Rule public final SlingContext context = new SlingContext(); -// @Test + // @Test public void successfulSave() throws Exception { Map<String, Object> params = new HashMap<String, Object>(); @@ -51,7 +53,7 @@ public class RatingPostServletTest { MockSlingHttpServletRequest request = context.request(); request.setRemoteUser("admin"); request.setParameterMap(params); - request.setResource(context.create().resource(SlingshotConstants.APP_ROOT_PATH+"/content/admin/travel")); + request.setResource(context.create().resource(SlingshotConstants.APP_ROOT_PATH + "/content/admin/travel")); MockSlingHttpServletResponse response = new MockSlingHttpServletResponse(); @@ -61,7 +63,5 @@ public class RatingPostServletTest { String output = response.getOutputAsString(); assertThat(output, equalTo("{ \"rating\" : 0}")); - } - } diff --git a/slingshot/src/test/java/org/apache/sling/sample/slingshot/ratings/impl/RatingServiceImplTest.java b/slingshot/src/test/java/org/apache/sling/sample/slingshot/ratings/impl/RatingServiceImplTest.java index 5c3a499..5a9e67d 100644 --- a/slingshot/src/test/java/org/apache/sling/sample/slingshot/ratings/impl/RatingServiceImplTest.java +++ b/slingshot/src/test/java/org/apache/sling/sample/slingshot/ratings/impl/RatingServiceImplTest.java @@ -1,31 +1,33 @@ /* - * 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 + * 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 + * 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. + * 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.sling.sample.slingshot.ratings.impl; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - import org.apache.sling.api.resource.Resource; import org.apache.sling.sample.slingshot.SlingshotConstants; import org.apache.sling.testing.mock.sling.junit.SlingContext; import org.junit.Rule; import org.junit.Test; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + public class RatingServiceImplTest { @Rule @@ -37,7 +39,8 @@ public class RatingServiceImplTest { context.load().json("/slingshot.json", SlingshotConstants.APP_ROOT_PATH); RatingsServiceImpl service = new RatingsServiceImpl(); - Resource resource = context.resourceResolver().getResource(SlingshotConstants.APP_ROOT_PATH+"/users/admin/hobby"); + Resource resource = + context.resourceResolver().getResource(SlingshotConstants.APP_ROOT_PATH + "/users/admin/hobby"); String ratingsResourcePath = service.getRatingsResourcePath(resource); assertThat(ratingsResourcePath, equalTo("/content/slingshot/users/admin/ugc/ratings/hobby")); @@ -49,11 +52,9 @@ public class RatingServiceImplTest { context.load().json("/slingshot.json", SlingshotConstants.APP_ROOT_PATH); RatingsServiceImpl service = new RatingsServiceImpl(); - Resource resource = context.resourceResolver().getResource(SlingshotConstants.APP_ROOT_PATH+"/users/admin"); + Resource resource = context.resourceResolver().getResource(SlingshotConstants.APP_ROOT_PATH + "/users/admin"); String ratingsResourcePath = service.getRatingsResourcePath(resource); assertThat(ratingsResourcePath, nullValue()); } - - }
