Rework sample app and update UI
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1735028 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/StreamInfo.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/StreamInfo.java
new file mode 100644
index 0000000..7a6c817
--- /dev/null
+++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/StreamInfo.java
@@ -0,0 +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
+ *
+ * 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.sling.sample.slingshot;
+
+
+public abstract class StreamInfo {
+
+ /** The resource type for a stream info. */
+ public static final String RESOURCETYPE = "slingshot/Streaminfo";
+
+ public static final String PROPERTY_TITLE = "title";
+
+ public static final String PROPERTY_DESCRIPTION = "description";
+
+ public static final String PATH_PHOTO = "photo";
+}
diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/User.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/User.java
new file mode 100644
index 0000000..9514802
--- /dev/null
+++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/User.java
@@ -0,0 +1,25 @@
+/*
+ * 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.sling.sample.slingshot;
+
+
+public abstract class User {
+
+ /** The resource type for a user. */
+ public static final String RESOURCETYPE = "slingshot/User";
+
+}
diff --git a/slingshot/src/main/java/org/apache/sling/sample/slingshot/UserInfo.java b/slingshot/src/main/java/org/apache/sling/sample/slingshot/UserInfo.java
new file mode 100644
index 0000000..3effe0d
--- /dev/null
+++ b/slingshot/src/main/java/org/apache/sling/sample/slingshot/UserInfo.java
@@ -0,0 +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
+ *
+ * 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.sling.sample.slingshot;
+
+
+public abstract class UserInfo {
+
+ /** The resource type for a user info. */
+ public static final String RESOURCETYPE = "slingshot/Userinfo";
+
+ public static final String PROPERTY_NAME = "name";
+
+ public static final String PROPERTY_ABOUT = "about";
+
+ public static final String PATH_PHOTO = "photo";
+}
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 9ff026a..366f303 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
@@ -17,8 +17,6 @@
package org.apache.sling.sample.slingshot.comments.impl;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
import javax.servlet.ServletException;
@@ -35,7 +33,6 @@
import org.apache.sling.sample.slingshot.comments.Comment;
import org.apache.sling.sample.slingshot.comments.CommentsService;
import org.apache.sling.sample.slingshot.comments.CommentsUtil;
-import org.apache.sling.sample.slingshot.impl.InternalConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,12 +64,7 @@
// save comment
ResourceResolver resolver = null;
try {
- // TODO - switch to service user with Oak
- final Map<String, Object> authInfo = new HashMap<String, Object>();
- authInfo.put(ResourceResolverFactory.USER, InternalConstants.SERVICE_USER_NAME);
- authInfo.put(ResourceResolverFactory.PASSWORD, InternalConstants.SERVICE_USER_NAME.toCharArray());
- resolver = factory.getResourceResolver(authInfo);
-// resolver = factory.getServiceResourceResolver(null);
+ resolver = factory.getServiceResourceResolver(null);
final Resource reqResource = resolver.getResource(request.getResource().getPath());
@@ -82,12 +74,12 @@
c.setCreatedBy(userId);
this.commentsService.addComment(reqResource, c);
-
+
// send redirect at the end
final String path = request.getResource().getPath();
- response.sendRedirect(resolver.map(request.getContextPath() + path + ".html"));
+ response.sendRedirect(resolver.map(request.getContextPath() + path + ".html"));
} catch ( final LoginException le ) {
throw new ServletException("Unable to login", le);
} finally {
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 27c90a6..660642d 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
@@ -133,23 +133,23 @@
}
private void setupUsers(final BundleContext bc, final ResourceResolver resolver) throws RepositoryException, IOException {
- final UserManager um = AccessControlUtil.getUserManager(resolver.adaptTo(Session.class));
+ final Session session = resolver.adaptTo(Session.class);
+ final UserManager um = AccessControlUtil.getUserManager(session);
for(final String userName : USERS) {
Authorizable user = um.getAuthorizable(userName);
if ( user == null ) {
logger.info("Creating user {}", userName);
um.createUser(userName, userName);
+ session.save();
}
}
// create a service user
Authorizable user = um.getAuthorizable(InternalConstants.SERVICE_USER_NAME);
if ( user == null ) {
- logger.info("Creating user {}", InternalConstants.SERVICE_USER_NAME);
- // TODO - jackrabbit 2 does not support creating a system user
- // um.createSystemUser(InternalConstants.SERVICE_USER_NAME, null);
-
- um.createUser(InternalConstants.SERVICE_USER_NAME, InternalConstants.SERVICE_USER_NAME);
+ logger.info("Creating service user {}", InternalConstants.SERVICE_USER_NAME);
+ um.createSystemUser(InternalConstants.SERVICE_USER_NAME, null);
+ session.save();
}
// check for service user config
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 40f9037..d5ef5af 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
@@ -18,8 +18,6 @@
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.Map;
import javax.servlet.ServletException;
@@ -33,7 +31,6 @@
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.sample.slingshot.SlingshotConstants;
-import org.apache.sling.sample.slingshot.impl.InternalConstants;
import org.apache.sling.sample.slingshot.ratings.RatingsService;
import org.apache.sling.sample.slingshot.ratings.RatingsUtil;
import org.slf4j.Logger;
@@ -68,12 +65,7 @@
// save rating
ResourceResolver resolver = null;
try {
- // TODO - switch to service user with Oak
- final Map<String, Object> authInfo = new HashMap<String, Object>();
- authInfo.put(ResourceResolverFactory.USER, InternalConstants.SERVICE_USER_NAME);
- authInfo.put(ResourceResolverFactory.PASSWORD, InternalConstants.SERVICE_USER_NAME.toCharArray());
- resolver = factory.getResourceResolver(authInfo);
-// resolver = factory.getServiceResourceResolver(null);
+ resolver = factory.getServiceResourceResolver(null);
final Resource reqResource = resolver.getResource(request.getResource().getPath());