Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more refactoring

  • Loading branch information...
commit cecd95ed2fad7466e958bd1479950e4d34992268 1 parent a10d2b2
@lincolnthree lincolnthree authored
Showing with 126 additions and 1,476 deletions.
  1. +1 −0  .gitignore
  2. +0 −92 src/main/java/com/ocpsoft/socialpm/domain/feed/FeedItem.java
  3. +1 −1  src/main/java/com/ocpsoft/socialpm/domain/feed/UserRegistered.java
  4. +2 −5 src/main/java/com/ocpsoft/socialpm/domain/user/Authority.java
  5. +5 −4 src/main/java/com/ocpsoft/socialpm/domain/user/User.java
  6. +0 −167 src/main/java/com/ocpsoft/socialpm/model/ChangeStoryPriority.java
  7. +11 −8 src/main/java/com/ocpsoft/socialpm/model/FeedService.java
  8. +0 −168 src/main/java/com/ocpsoft/socialpm/model/IterationService.java
  9. +0 −333 src/main/java/com/ocpsoft/socialpm/model/ProjectService.java
  10. +0 −206 src/main/java/com/ocpsoft/socialpm/model/StoryService.java
  11. +18 −14 src/main/java/com/ocpsoft/socialpm/model/UserService.java
  12. +1 −20 src/main/java/com/ocpsoft/socialpm/pages/admin/AdminBean.java
  13. +3 −1 src/main/java/com/ocpsoft/socialpm/pages/profile/UserAccountBean.java
  14. +0 −52 src/main/java/com/ocpsoft/socialpm/validator/CheckboxRequiredValidator.java
  15. +0 −71 src/main/java/com/ocpsoft/socialpm/validator/CurrentUserPasswordValidator.java
  16. +0 −64 src/main/java/com/ocpsoft/socialpm/validator/EmailAvailabilityValidator.java
  17. +0 −55 src/main/java/com/ocpsoft/socialpm/validator/EmailValidator.java
  18. +0 −56 src/main/java/com/ocpsoft/socialpm/validator/PasswordValidator.java
  19. +0 −64 src/main/java/com/ocpsoft/socialpm/validator/UsernameAvailabilityValidator.java
  20. +0 −56 src/main/java/com/ocpsoft/socialpm/validator/UsernameValidator.java
  21. +2 −2 src/main/resources/META-INF/persistence.xml
  22. +2 −2 src/main/webapp/WEB-INF/ejb-jar.xml
  23. +4 −0 src/main/webapp/WEB-INF/pretty-config.xml
  24. +1 −1  src/main/webapp/WEB-INF/view/elements/login/loginForm.xhtml
  25. +5 −5 src/main/webapp/WEB-INF/view/elements/mainMenu.xhtml
  26. +3 −2 src/main/webapp/WEB-INF/view/templates/socialpm.xhtml
  27. +14 −13 src/main/webapp/pages/profile/userAccount.xhtml
  28. +4 −6 src/main/webapp/pages/profile/userProfile.xhtml
  29. +0 −1  src/main/webapp/resources/ocpcommon/messages.xhtml
  30. +49 −7 src/test/java/com/ocpsoft/socialpm/model/UserServiceTest.java
View
1  .gitignore
@@ -5,3 +5,4 @@
*target/*
*.jsfdia
*.swp
+transaction.log
View
92 src/main/java/com/ocpsoft/socialpm/domain/feed/FeedItem.java
@@ -1,92 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.domain.feed;
-
-import javax.persistence.DiscriminatorColumn;
-import javax.persistence.DiscriminatorType;
-import javax.persistence.DiscriminatorValue;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-
-import com.ocpsoft.socialpm.domain.PersistentObject;
-import com.ocpsoft.socialpm.domain.project.Project;
-import com.ocpsoft.socialpm.domain.user.User;
-
-@Entity
-@Table(name = "activity_feed")
-@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
-@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, length = 15)
-@DiscriminatorValue("basic")
-public class FeedItem extends PersistentObject<FeedItem>
-{
- private static final long serialVersionUID = 7038341222060982180L;
-
- @OneToOne
- private Project project;
-
- @OneToOne
- private User user;
-
- protected FeedItem()
- {
- }
-
- public FeedItem(final Project project, final User user)
- {
- this.project = project;
- this.user = user;
- }
-
- public Project getProject()
- {
- return project;
- }
-
- public FeedItem setProject(final Project project)
- {
- this.project = project;
- return this;
- }
-
- public User getUser()
- {
- return user;
- }
-
- public FeedItem setUser(final User user)
- {
- this.user = user;
- return this;
- }
-}
View
2  src/main/java/com/ocpsoft/socialpm/domain/feed/UserRegistered.java
@@ -37,7 +37,7 @@
@Entity
@DiscriminatorValue("userregistered")
-public class UserRegistered extends FeedItem
+public class UserRegistered extends FeedEvent
{
private static final long serialVersionUID = -281646598510177402L;
View
7 src/main/java/com/ocpsoft/socialpm/domain/user/Authority.java
@@ -39,8 +39,6 @@
import javax.persistence.InheritanceType;
import javax.persistence.Table;
-import org.hibernate.annotations.Index;
-
import com.ocpsoft.socialpm.domain.PersistentObject;
@Entity
@@ -52,15 +50,14 @@
{
private static final long serialVersionUID = 5317479113915801691L;
- @Index(name = "authAuthIndex1")
- @Column(updatable = false, length = 64)
+ @Column(name = "custom_auth_key", updatable = false, length = 64)
private String key;
public Authority()
{
}
- public Authority(String key)
+ public Authority(final String key)
{
this.key = key;
}
View
9 src/main/java/com/ocpsoft/socialpm/domain/user/User.java
@@ -60,8 +60,9 @@
@Entity
@Table(name = "users")
@NamedQueries({
- @NamedQuery(name = "user.byEmail", query = "from User where email = ?"),
- @NamedQuery(name = "user.byName", query = "from User where username = ?") })
+ @NamedQuery(name = "user.byEmail", query = "from User where email = ?"),
+ @NamedQuery(name = "user.byRegKey", query = "from User where registrationKey = ?"),
+ @NamedQuery(name = "user.byName", query = "from User where username = ?") })
public class User extends PersistentObject<User>
{
@Transient
@@ -195,7 +196,7 @@ public UserProfile getProfile()
return profile;
}
- public void setProfile(UserProfile profile)
+ public void setProfile(final UserProfile profile)
{
this.profile = profile;
}
@@ -205,7 +206,7 @@ public String getRegistrationKey()
return registrationKey;
}
- public void setRegistrationKey(String registrationKey)
+ public void setRegistrationKey(final String registrationKey)
{
this.registrationKey = registrationKey;
}
View
167 src/main/java/com/ocpsoft/socialpm/model/ChangeStoryPriority.java
@@ -1,167 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.model;
-
-import javax.ejb.Stateful;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceContextType;
-import javax.persistence.Query;
-
-import com.ocpsoft.socialpm.domain.PersistenceUtil;
-import com.ocpsoft.socialpm.domain.project.stories.Story;
-
-@Stateful
-public class ChangeStoryPriority extends PersistenceUtil
-{
- private static final long serialVersionUID = -5136445178219428141L;
-
- @PersistenceContext(type = PersistenceContextType.EXTENDED)
- private EntityManager entityManager;
-
- @Override
- protected EntityManager getEntityManager()
- {
- return entityManager;
- }
-
- public Story execute(final Story story, final Integer newPriority)
- {
- // TODO lb3 This should be chain of responsibility... ART
- Story temp = story;
- Integer currentMax = getMaxPriority(temp);
- Integer newValue = newPriority;
- Integer oldValue = temp.getPriority();
-
- // ensure integer values >= 1
- if ((newValue != null) && (newValue <= 0))
- {
- newValue = 1;
- }
-
- // do nothing case
- if ((newValue == oldValue) || ((newValue != null) && newValue.equals(oldValue)))
- {
- return null;
- }
-
- // set first value case
- if (currentMax == null)
- {
- newValue = 1;
- temp.setPriority(newValue);
- this.save(temp);
- return null;
- }
-
- // set null to any greater value case
- if ((newValue != null) && (currentMax.compareTo(newValue) < 0) && (oldValue == null))
- {
- newValue = currentMax + 1;
- temp.setPriority(newValue);
- this.save(temp);
- return null;
- }
-
- Query query;
-
- // shift up case
- if ((oldValue != null) && (newValue != null) && (oldValue > newValue))
- {
- // shift >= newpriority && < oldpriority ++
- query = getEntityManager().createQuery("UPDATE Story s SET s.priority = s.priority + 1 " + "WHERE s.project = :project AND s.priority >= :newPriority " + "AND s.priority < :oldPriority");
- query.setParameter("newPriority", newValue);
- query.setParameter("oldPriority", oldValue);
- query.setParameter("project", temp.getProject());
- query.executeUpdate();
-
- temp.setPriority(newValue);
- this.save(temp);
- return null;
- }
-
- if ((oldValue == null) || ((newValue != null) && (oldValue > newValue)))
- {
- // shift >= newpriority ++
- query = getEntityManager().createQuery("UPDATE Story s SET s.priority = s.priority + 1 " + "WHERE s.project = :project AND s.priority >= :newPriority");
- query.setParameter("newPriority", newValue);
- query.setParameter("project", temp.getProject());
- query.executeUpdate();
-
- temp.setPriority(newValue);
- this.save(temp);
- return null;
- }
-
- // set shift down case
- if (newValue == null)
- {
- // shift <= newpriority && > oldpriority--
- query = getEntityManager().createQuery("UPDATE Story s SET s.priority = s.priority - 1 " + "WHERE s.project = :project AND s.priority > :oldPriority");
- query.setParameter("oldPriority", oldValue);
- query.setParameter("project", temp.getProject());
- query.executeUpdate();
-
- temp.setPriority(newValue);
- this.save(temp);
- return null;
- }
-
- if (oldValue < newValue)
- {
- // shift <= newpriority && > oldpriority--
- query = getEntityManager().createQuery("UPDATE Story s SET s.priority = s.priority - 1 " + "WHERE s.project = :project AND s.priority <= :newPriority AND s.priority > :oldPriority");
- query.setParameter("newPriority", newValue);
- query.setParameter("oldPriority", oldValue);
- query.setParameter("project", temp.getProject());
- query.executeUpdate();
-
- temp.setPriority(newValue);
- this.save(temp);
- return null;
- }
-
- throw new IllegalStateException("Invalid priority change scenario.. missed case?");
- }
-
- private Integer getMaxPriority(final Story story)
- {
- javax.persistence.Query query = getEntityManager().createQuery("SELECT MAX(s.priority) FROM Story s WHERE s.project = :project");
- query.setParameter("project", story.getProject());
- Integer uniqueResult = (Integer) query.getSingleResult();
-
- if (uniqueResult == null)
- {
- return null;
- }
- return uniqueResult.intValue();
- }
-}
View
19 src/main/java/com/ocpsoft/socialpm/model/FeedService.java
@@ -30,15 +30,18 @@
package com.ocpsoft.socialpm.model;
+import java.util.Date;
import java.util.List;
import javax.ejb.Stateful;
+import javax.enterprise.event.Observes;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import com.ocpsoft.socialpm.domain.PersistenceUtil;
-import com.ocpsoft.socialpm.domain.feed.FeedItem;
+import com.ocpsoft.socialpm.domain.feed.FeedEvent;
+import com.ocpsoft.socialpm.domain.user.User;
@Stateful
public class FeedService extends PersistenceUtil
@@ -54,19 +57,19 @@ protected EntityManager getEntityManager()
return entityManager;
}
- public List<FeedItem> list(final int limit, final int offset)
+ public void addEvent(@Observes final FeedEvent event)
{
- return this.findAll(FeedItem.class);
+ event.setCreatedOn(new Date());
+ save(event);
}
- public List<FeedItem> listByUser(final Long id, final int limit, final int offset)
+ public List<FeedEvent> list(final int limit, final int offset)
{
- return this.findByNamedQuery("feedItem.byUser", id);
+ return this.findAll(FeedEvent.class);
}
- public List<FeedItem> listByProject(final Long id, final int limit, final int offset)
+ public List<FeedEvent> listByUser(final User user, final int limit, final int offset)
{
- return this.findByNamedQuery("feedItem.byProject", id);
+ return this.findByNamedQuery("feedItem.byUser", user);
}
-
}
View
168 src/main/java/com/ocpsoft/socialpm/model/IterationService.java
@@ -1,168 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.model;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Set;
-
-import javax.ejb.Stateful;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceContextType;
-
-import com.ocpsoft.socialpm.domain.PersistenceUtil;
-import com.ocpsoft.socialpm.domain.project.Project;
-import com.ocpsoft.socialpm.domain.project.iteration.Iteration;
-import com.ocpsoft.socialpm.domain.project.stories.Story;
-import com.ocpsoft.socialpm.model.project.DailyStatsChain;
-import com.ocpsoft.socialpm.util.Dates;
-
-@Stateful
-public class IterationService extends PersistenceUtil
-{
- private static final long serialVersionUID = 871813809364378710L;
-
- @PersistenceContext(type = PersistenceContextType.EXTENDED)
- private EntityManager entityManager;
-
- @Override
- protected EntityManager getEntityManager()
- {
- return entityManager;
- }
-
- /**
- * Commit the specified iteration
- *
- * @throws IllegalStateException if the iteration is already committed,
- * IllegalArgumentException if the iteration hasn't started, or
- * the iteration has finished, or the iteration is Default past
- */
- public void commit(final Iteration iteration) throws IllegalStateException, IllegalArgumentException
- {
- Date today = Dates.now();
-
- if (iteration.isCommitted())
- {
- throw new IllegalStateException("Iteration: " + iteration.getTitle() + " has already been committed");
- }
- else if (!iteration.isDefault() && Dates.isInPrecisionRange(iteration.getStartDate(), iteration.getEndDate(), today, Calendar.DATE))
- {
- iteration.updateCommitmentStats();
- iteration.setCommittedOn(Dates.now());
- this.save(iteration);
- }
- else
- {
- String errorMessage = "Commit is not allowed on Iteration: " + iteration.getTitle();
-
- if (iteration.isDefault())
- {
- errorMessage += " because it is the Default.";
- }
- else if (iteration.isEnded())
- {
- errorMessage += " because the iteration has completed.";
- }
- else if (!iteration.isEnded())
- {
- errorMessage += " because the iteration has not started yet.";
- }
-
- throw new IllegalArgumentException(errorMessage);
- }
- }
-
- /**
- * Move a story from one Iteration to another. If from is a future iteration
- * remove this Story's relationship with From. If From is the Default
- * Iteration, its relationship is always removed.
- *
- * @throws IllegalStateException if To has ended, IllegalArgumentException if
- * to is in the past
- */
- public void changeStoryIteration(final Iteration to, final Story story) throws IllegalStateException, IllegalArgumentException
- {
- Iteration from = story.getIteration();
- if (from.equals(to))
- {
- save(story);
- return;
- }
-
- if (to.isEnded())
- {
- throw new IllegalArgumentException("Cannot change iteration history: Iteration [" + to + "] is in the past");
- }
-
- if (!from.isEnded())
- {
- from.getStories().remove(story);
- updateIterationStatistics(from);
- }
-
- story.setIteration(to);
- to.getStories().add(story);
- this.save(story);
- updateIterationStatistics(to);
- this.save(from);
- }
-
- /**
- * @throws IllegalArgumentException if Iteration has ended
- */
- public void updateIterationStatistics(final Iteration iteration) throws IllegalStateException
- {
- DailyStatsChain.getInstance().update(iteration);
- this.save(iteration);
- }
-
- public void removeIteration(final Iteration iteration)
- {
- Project project = iteration.getProject();
-
- if (iteration.isDefault())
- {
- throw new IllegalArgumentException("Cannot remove a project's default iteration.");
- }
-
- Set<Story> stories = iteration.getStories();
- for (Story s : stories)
- {
- project.getDefaultIteration().getStories().add(s);
- }
-
- iteration.getProject().getIterations().remove(iteration);
- this.save(iteration);
- }
-
-}
View
333 src/main/java/com/ocpsoft/socialpm/model/ProjectService.java
@@ -1,333 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.model;
-
-import java.util.List;
-
-import javax.ejb.Stateful;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceContextType;
-import javax.persistence.PersistenceException;
-import javax.persistence.Query;
-
-import com.ocpsoft.socialpm.domain.PersistenceUtil;
-import com.ocpsoft.socialpm.domain.project.Feature;
-import com.ocpsoft.socialpm.domain.project.MemberRole;
-import com.ocpsoft.socialpm.domain.project.Membership;
-import com.ocpsoft.socialpm.domain.project.Milestone;
-import com.ocpsoft.socialpm.domain.project.Points;
-import com.ocpsoft.socialpm.domain.project.Project;
-import com.ocpsoft.socialpm.domain.project.iteration.Iteration;
-import com.ocpsoft.socialpm.domain.project.stories.Story;
-import com.ocpsoft.socialpm.domain.project.stories.StoryStatus;
-import com.ocpsoft.socialpm.domain.project.stories.Task;
-import com.ocpsoft.socialpm.domain.project.stories.TaskStatus;
-import com.ocpsoft.socialpm.domain.user.User;
-import com.ocpsoft.socialpm.util.Strings;
-
-@Stateful
-public class ProjectService extends PersistenceUtil
-{
- private static final long serialVersionUID = 6301111544805213272L;
-
- @PersistenceContext(type = PersistenceContextType.EXTENDED)
- private EntityManager entityManager;
-
- @Override
- protected EntityManager getEntityManager()
- {
- return entityManager;
- }
-
- @Inject
- private IterationService is;
-
- @Inject
- StoryService ss;
-
- @SuppressWarnings("unchecked")
- public List<Project> list(final int limit, final int offset)
- {
- Query query = getEntityManager().createNamedQuery("project.list", Project.class);
- query.setFirstResult(offset);
- query.setMaxResults(limit);
- return query.getResultList();
- }
-
- public int getProjectCount()
- {
- return ((Long) this.findUniqueByNamedQuery("project.count")).intValue();
- }
-
- public Project getByName(final String name)
- {
- return this.findUniqueByNamedQuery("project.byCanonicalName", Strings.canonicalize(name));
- }
-
- public void createProject(final User owner, final Project project)
- {
- project.setCanonicalName(Strings.canonicalize(project.getName()));
-
- this.create(project);
-
- Iteration iteration = new Iteration();
- iteration.setTitle("Unassigned");
- addIteration(project, iteration);
-
- Feature feature = new Feature();
- feature.setName("Bug Fixes");
- addFeature(project, feature);
-
- feature = new Feature();
- feature.setName("Enhancements");
- addFeature(project, feature);
-
- feature = new Feature();
- feature.setName("Unclassified");
- addFeature(project, feature);
-
- addMembership(project, new Membership(project, owner, MemberRole.OWNER));
-
- this.save(project);
- }
-
- private void addMembership(final Project project, final Membership membership)
- {
- project.getMemberships().add(membership);
- membership.setProject(project);
- this.create(membership);
- }
-
- public void saveProjectDetails(final long projectId, final Project project)
- {
- Project p = this.findById(Project.class, projectId);
- p.setVision(project.getVision());
- p.setGoals(project.getGoals());
- p.setObjectives(project.getObjectives());
- this.save(p);
- }
-
- public void inviteMember(final long projectId, final long userId)
- {
- Project project = this.findById(Project.class, projectId);
- User user = this.findById(User.class, userId);
-
- if (!project.getAllMembers().contains(user))
- {
- Membership membership = new Membership(project, user, MemberRole.INVITED);
- project.getMemberships().add(membership);
- }
- this.save(project);
- }
-
- public void requestMembership(final Project project, final User user)
- {
- if (!project.getAllMembers().contains(user))
- {
- Membership membership = new Membership(project, user, MemberRole.REQUESTED);
- project.getMemberships().add(membership);
- }
- this.save(project);
- }
-
- public void setMemberRole(final Project project, final User user, final MemberRole role)
- {
- Membership member = project.getMembership(user);
- member.setRole(role);
- this.save(member);
- }
-
- public void leaveProject(final Project project, final User user)
- {
- Membership member = project.getMembership(user);
- if (project.getOwners().size() >= 1)
- {
- removeTaskAssignments(project, user);
- project.getMemberships().remove(member);
- this.delete(member);
- }
- else
- {
- // TODO handle this with nice client exception message
- throw new PersistenceException("Cannot remove last Owner of a Project");
- }
- }
-
- @SuppressWarnings("unchecked")
- private void removeTaskAssignments(final Project project, final User user)
- {
- Query query = getEntityManager().createQuery("FROM Task t WHERE t.story.project = :project");
- query.setParameter("project", project);
- List<Task> tasks = query.getResultList();
-
- query = getEntityManager().createQuery("UPDATE Task t SET t.assignee = null WHERE t.assignee = :user " + "AND t.status <> :status AND t IN (:list)");
- query.setParameter("user", user);
- query.setParameter("status", TaskStatus.DONE);
- query.setParameter("list", tasks);
- query.executeUpdate();
- }
-
- public void addStory(final Project project, final Iteration iteration, final Story story)
- {
- story.setProject(project);
- project.getStories().add(story);
-
- if (story.getStoryPoints() == null)
- {
- story.setStoryPoints(Points.NOT_POINTED);
- }
-
- if (story.getBusinessValue() == null)
- {
- story.setBusinessValue(Points.NOT_POINTED);
- }
-
- story.setStatus(StoryStatus.OPEN);
-
- /*
- * For some reason, these operations must take place in the following
- * order, otherwise iterations are not added to the history collection.
- */
- iteration.getStories().add(story);
- story.setIteration(iteration);
- create(story);
- refresh(story);
-
- is.updateIterationStatistics(iteration);
- }
-
- public Story getStory(final Project project, final int storyNumber)
- {
- Story s = this.findUniqueByNamedQuery("Story.byProjectAndNumber", project.getId(), storyNumber);
- return s;
- }
-
- public List<Story> getStories(final long projectId)
- {
- return this.findByNamedQuery("Story.byProjectId", projectId);
- }
-
- public List<Story> getStoriesByFeature(final long projectId, final long featureId)
- {
- return this.findByNamedQuery("Story.byProjectAndFeatureId", projectId, featureId);
- }
-
- public List<Story> getFrontBurnerStories(final long projectId, final long iterationId)
- {
- Iteration iteration = this.findById(Iteration.class, iterationId);
- return iteration.getFrontShelfStories();
- }
-
- public void addFeature(final Project project, final Feature feature)
- {
- project.getFeatures().add(feature);
- feature.setProject(project);
- this.create(feature);
- }
-
- public void removeFeature(final Project project, final Feature feature)
- {
- if (feature.getProject().equals(project))
- {
- project.getFeatures().remove(feature);
- feature.setProject(null);
- }
- save(project);
- }
-
- public int mergeFeatures(final Feature from, final Feature to)
- {
- assert from.getProject().equals(to.getProject());
-
- Query query = getEntityManager().createQuery("update Story set feature = :newFeature where feature = :oldFeature");
- query.setParameter("newFeature", to);
- query.setParameter("oldFeature", from);
- int updated = query.executeUpdate();
-
- from.getProject().getFeatures().remove(from);
- this.delete(from);
-
- return updated;
- }
-
- public void addIteration(final Project project, final Iteration iteration)
- {
- project.getIterations().add(iteration);
- iteration.setProject(project);
- this.save(project);
- }
-
- public void commitIteration(final long projectId, final long iterationId)
- {
- Iteration iteration = this.findById(Iteration.class, iterationId);
- is.commit(iteration);
- }
-
- public void removeIteration(final long projectId, final long iterationId)
- {
- Iteration iteration = this.findById(Iteration.class, iterationId);
- is.removeIteration(iteration);
- }
-
- public void addMilestone(final Project project, final Milestone milestone)
- {
- milestone.setProject(project);
- project.getMilestones().add(milestone);
- save(project);
- }
-
- public void saveMilestone(final long projectId, final Milestone milestone)
- {
- Milestone m = this.findById(Milestone.class, milestone.getId());
-
- m.setTargetDate(milestone.getTargetDate());
- m.setDescription(milestone.getDescription());
- m.setName(milestone.getName());
-
- this.save(m);
- }
-
- public void removeMilestone(final Project project, final Milestone milestone)
- {
- for (Story s : milestone.getStories())
- {
- s.setMilestone(null);
- milestone.getStories().remove(s);
- }
-
- milestone.getProject().getMilestones().remove(milestone);
- milestone.setProject(null);
-
- this.delete(milestone);
- }
-}
View
206 src/main/java/com/ocpsoft/socialpm/model/StoryService.java
@@ -1,206 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.model;
-
-import java.util.Date;
-
-import javax.ejb.Stateful;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceContextType;
-
-import com.ocpsoft.socialpm.domain.NoSuchObjectException;
-import com.ocpsoft.socialpm.domain.PersistenceUtil;
-import com.ocpsoft.socialpm.domain.project.Milestone;
-import com.ocpsoft.socialpm.domain.project.iteration.Iteration;
-import com.ocpsoft.socialpm.domain.project.stories.Story;
-import com.ocpsoft.socialpm.domain.project.stories.StoryComment;
-import com.ocpsoft.socialpm.domain.project.stories.StoryStatus;
-import com.ocpsoft.socialpm.domain.project.stories.Task;
-import com.ocpsoft.socialpm.domain.project.stories.TaskStatus;
-import com.ocpsoft.socialpm.domain.project.stories.ValidationCriteria;
-import com.ocpsoft.socialpm.domain.user.User;
-
-@Stateful
-public class StoryService extends PersistenceUtil
-{
- private static final long serialVersionUID = -7326281066237817776L;
-
- @PersistenceContext(type = PersistenceContextType.EXTENDED)
- private EntityManager entityManager;
-
- @Override
- protected EntityManager getEntityManager()
- {
- return entityManager;
- }
-
- @Inject
- private IterationService is;
-
- @Inject
- private ChangeStoryPriority changePriority;
-
- public void saveStoryDetails(final Story story)
- {
- if (StoryStatus.CLOSED.equals(story.getStatus()))
- {
- for (Task t : story.getTasks())
- {
- if (!TaskStatus.DONE.equals(t.getStatus()))
- {
- t.close();
- }
- }
- }
-
- this.save(story);
- is.updateIterationStatistics(story.getIteration());
- }
-
- public void changeIteration(final Story story, final Iteration iteration)
- {
- is.changeStoryIteration(iteration, story);
- }
-
- public Story addComment(final Story story, final StoryComment comment)
- {
- story.getComments().add(comment);
- this.create(comment);
- return story;
- }
-
- public void removeComment(final StoryComment comment)
- {
- comment.getStory().getComments().remove(comment);
- comment.setStory(null);
- save(comment.getStory());
- }
-
- public Story addTask(final Story story, final Task task)
- {
- task.setStatus(TaskStatus.NOT_STARTED);
- task.setInitialHours(task.getInitialHours());
-
- task.setStory(story);
- story.getTasks().add(task);
-
- this.create(task);
- is.updateIterationStatistics(story.getIteration());
- return story;
- }
-
- public void deleteTask(final Task task)
- {
- Story story = task.getStory();
- story.getTasks().remove(task);
- task.setStory(null);
- this.save(story);
- is.updateIterationStatistics(story.getIteration());
- }
-
- public void saveTask(final Task task)
- {
- if (TaskStatus.DONE.equals(task.getStatus()))
- {
- task.close();
- }
-
- User assignee = task.getAssignee();
- if ((assignee != null) && task.getStory().getProject().hasActiveMember(assignee))
- {
- throw new NoSuchObjectException("Assignee was not found in project");
- }
-
- this.save(task);
- is.updateIterationStatistics(task.getStory().getIteration());
- }
-
- public void addValidation(final Story story, final ValidationCriteria validation)
- {
- validation.setStory(story);
- story.getValidations().add(validation);
- this.save(story);
- }
-
- public void saveValidationDescription(final ValidationCriteria v)
- {
- this.save(v);
- }
-
- public void removeValidation(final ValidationCriteria validation)
- {
- validation.getStory().getValidations().remove(validation);
- this.delete(validation);
- }
-
- public void acceptValidation(final ValidationCriteria validation, final User user)
- {
- validation.setAccepted(true);
- validation.setAcceptedBy(user);
- validation.setAcceptedOn(new Date());
- this.save(validation);
- }
-
- public void rejectValidation(final ValidationCriteria validation)
- {
- validation.setAccepted(false);
- validation.setAcceptedBy(null);
- validation.setAcceptedOn(null);
- this.save(validation);
- }
-
- public void changePriority(final long storyId, final Integer newPriority)
- {
- Story story = this.findById(Story.class, storyId);
- changePriority.execute(story, newPriority);
- }
-
- public void setStoryMilestone(final Story story, final Milestone milestone)
- {
- story.setMilestone(milestone);
- milestone.getStories().add(story);
-
- this.save(milestone);
- }
-
- public void removeStoryMilestone(final Story story)
- {
- Milestone milestone = story.getMilestone();
- if (milestone != null)
- {
- milestone.getStories().remove(story);
- story.setMilestone(null);
- this.save(milestone);
- }
- }
-}
View
32 src/main/java/com/ocpsoft/socialpm/model/UserService.java
@@ -34,12 +34,13 @@
import java.util.List;
import javax.ejb.Stateful;
+import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
-import javax.persistence.Query;
import com.ocpsoft.socialpm.domain.PersistenceUtil;
+import com.ocpsoft.socialpm.domain.feed.UserRegistered;
import com.ocpsoft.socialpm.domain.user.Authority;
import com.ocpsoft.socialpm.domain.user.User;
import com.ocpsoft.socialpm.domain.user.UserPasswordMatchTester;
@@ -61,6 +62,9 @@
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager em;
+ @Inject
+ private FeedService fs;
+
@Override
protected EntityManager getEntityManager()
{
@@ -72,7 +76,7 @@ protected EntityManager getEntityManager()
return findAll(User.class);
}
- public void save(User user)
+ public void save(final User user)
{
super.save(user);
}
@@ -93,13 +97,14 @@ public User getUserByEmail(final String email)
}
/**
- * Take a user object with populated username and plaintext password.
- * Register that user, and return the pending registration key with which the
- * user must be verified.
+ * Take a user object with populated username and plaintext password. Register that user, and return the pending
+ * registration key with which the user must be verified.
*/
public String registerUser(final User user)
{
- Assert.isTrue(StringValidations.isAlphanumeric(user.getUsername()) && StringValidations.minLength(4, user.getUsername()) && StringValidations.maxLength(15, user.getUsername()));
+ Assert.isTrue(StringValidations.isAlphanumeric(user.getUsername())
+ && StringValidations.minLength(4, user.getUsername())
+ && StringValidations.maxLength(15, user.getUsername()));
Assert.isTrue(StringValidations.isPassword(user.getPassword()));
Assert.isTrue(StringValidations.isEmailAddress(user.getEmail()));
@@ -114,10 +119,12 @@ public String registerUser(final User user)
user.setRegistrationKey(RandomGenerator.makeString());
create(user);
+
+ fs.addEvent(new UserRegistered(user));
return user.getRegistrationKey();
}
- public void enableAccount(final User user, String password)
+ public void enableAccount(final User user, final String password)
{
if (!user.isEnabled() && passwordIs(user, password))
{
@@ -126,19 +133,16 @@ public void enableAccount(final User user, String password)
save(user);
}
- public User verifyUser(String key)
+ public User verifyUser(final String key)
{
- Query query = em.createQuery("from User where registrationKey=:key");
- query.setParameter("key", key);
-
- User user = (User) query.getSingleResult();
+ User user = findUniqueByNamedQuery("user.byRegKey", key);
user.getAuthorities().add(new UserVerified());
save(user);
return user;
}
- public void disableAccount(User user)
+ public void disableAccount(final User user)
{
user.getAuthorities().remove(new UserEnabled());
save(user);
@@ -156,7 +160,7 @@ public boolean passwordIs(final User user, final String password)
return new UserPasswordMatchTester().passwordMatches(user, password);
}
- public boolean updatePassword(User user, final String oldPassword, final String newPassword)
+ public boolean updatePassword(final User user, final String oldPassword, final String newPassword)
{
if (new UserPasswordMatchTester().passwordMatches(user, oldPassword))
{
View
21 src/main/java/com/ocpsoft/socialpm/pages/admin/AdminBean.java
@@ -42,11 +42,9 @@
import org.jboss.seam.international.status.Messages;
import com.ocpsoft.socialpm.domain.NoSuchObjectException;
-import com.ocpsoft.socialpm.domain.project.Project;
import com.ocpsoft.socialpm.domain.user.Authority;
import com.ocpsoft.socialpm.domain.user.User;
import com.ocpsoft.socialpm.domain.user.auth.Role;
-import com.ocpsoft.socialpm.model.ProjectService;
import com.ocpsoft.socialpm.model.UserService;
import com.ocpsoft.socialpm.web.constants.ApplicationConfig;
@@ -60,9 +58,6 @@
private boolean initialized = false;
@Inject
- private ProjectService ps;
-
- @Inject
private UserService us;
@Inject
@@ -97,7 +92,7 @@ public boolean isDatabaseInitialized()
return initialized;
}
- public void setupApp(@Observes @Before @RestoreView PhaseEvent event)
+ public void setupApp(@Observes @Before @RestoreView final PhaseEvent event)
{
if (!isDatabaseInitialized())
{
@@ -115,20 +110,6 @@ public void setupApp(@Observes @Before @RestoreView PhaseEvent event)
us.registerUser(lb);
us.addAuthority(lb, new Authority(Role.ADMIN.value()));
- Project project = new Project();
- project.setName("Demo Project");
- project.setVision("Be visionary");
- ps.createProject(lb, project);
-
- // Story s = new Story();
- // s.setDescription("This is a sample story.");
- // s.setFeature(project.getFeature("Unclassified"));
- // s.setStoryPoints(Points.S8);
- // s.setBurner(StoryBurner.FRONT);
- // ps.addStory(project, project.getDefaultIteration(), s);
- // ss.addValidation(s, new
- // ValidationCriteria("Sample validation criteria"));
-
User user = new User();
user.setEmail("demo@ocpsoft.com");
user.setUsername("demo");
View
4 src/main/java/com/ocpsoft/socialpm/pages/profile/UserAccountBean.java
@@ -81,10 +81,12 @@ public String save()
public String cancel()
{
+ messages.info("Changes to your private stuff have been discarded.");
return UrlConstants.USER_PROFILE;
}
- public void validateNewEmail(final FacesContext context, final UIComponent component, final Object value) throws ValidatorException
+ public void validateNewEmail(final FacesContext context, final UIComponent component, final Object value)
+ throws ValidatorException
{
if (!user.getEmail().equals(value))
{
View
52 src/main/java/com/ocpsoft/socialpm/validator/CheckboxRequiredValidator.java
@@ -1,52 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.validator;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.Validator;
-import javax.faces.validator.ValidatorException;
-
-@FacesValidator("checkboxRequiredValidator")
-public class CheckboxRequiredValidator implements Validator
-{
- @Override
- public void validate(final FacesContext context, final UIComponent component, final Object value) throws ValidatorException
- {
- if (!Boolean.TRUE.equals(value))
- {
- FacesMessage msg = new FacesMessage("Required");
- throw new ValidatorException(msg);
- }
- }
-}
View
71 src/main/java/com/ocpsoft/socialpm/validator/CurrentUserPasswordValidator.java
@@ -1,71 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.validator;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.Validator;
-import javax.faces.validator.ValidatorException;
-import javax.inject.Inject;
-
-import com.ocpsoft.socialpm.domain.user.User;
-import com.ocpsoft.socialpm.model.UserService;
-import com.ocpsoft.socialpm.security.LoggedIn;
-
-@FacesValidator("currentUserPasswordValidator")
-public class CurrentUserPasswordValidator implements Validator
-{
- @Inject
- @LoggedIn
- User user;
-
- @Inject
- UserService us;
-
- @Override
- public void validate(final FacesContext context, final UIComponent component, final Object value) throws ValidatorException
- {
- String password = "";
- if (value != null)
- {
- password = value.toString();
- }
-
- boolean passwordMatches = us.passwordIs(user, password);
- if (password.isEmpty() || !passwordMatches)
- {
- FacesMessage msg = new FacesMessage("Passwords do not match");
- throw new ValidatorException(msg);
- }
- }
-}
View
64 src/main/java/com/ocpsoft/socialpm/validator/EmailAvailabilityValidator.java
@@ -1,64 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.validator;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.Validator;
-import javax.faces.validator.ValidatorException;
-import javax.inject.Inject;
-
-import com.ocpsoft.socialpm.domain.NoSuchObjectException;
-import com.ocpsoft.socialpm.model.UserService;
-
-@FacesValidator("emailAvailabilityValidator")
-public class EmailAvailabilityValidator implements Validator
-{
- @Inject
- UserService us;
-
- @Override
- public void validate(final FacesContext context, final UIComponent component, final Object value) throws ValidatorException
- {
- String field = value.toString();
- try
- {
- us.getUserByEmail(field);
- FacesMessage msg = new FacesMessage("That email address is unavailable");
- throw new ValidatorException(msg);
- }
- catch (NoSuchObjectException e)
- {
- }
- }
-}
View
55 src/main/java/com/ocpsoft/socialpm/validator/EmailValidator.java
@@ -1,55 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.validator;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.Validator;
-import javax.faces.validator.ValidatorException;
-
-import com.ocpsoft.socialpm.util.StringValidations;
-
-@FacesValidator("emailValidator")
-public class EmailValidator implements Validator
-{
- @Override
- public void validate(final FacesContext context, final UIComponent component, final Object value) throws ValidatorException
- {
- String field = value.toString();
- if (!StringValidations.isEmailAddress(field) || !StringValidations.maxLength(256, field))
- {
- FacesMessage msg = new FacesMessage("Must be a valid email address");
- throw new ValidatorException(msg);
- }
- }
-}
View
56 src/main/java/com/ocpsoft/socialpm/validator/PasswordValidator.java
@@ -1,56 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.validator;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.Validator;
-import javax.faces.validator.ValidatorException;
-
-import com.ocpsoft.socialpm.util.StringValidations;
-
-@FacesValidator("passwordValidator")
-public class PasswordValidator implements Validator
-{
-
- @Override
- public void validate(final FacesContext context, final UIComponent component, final Object value) throws ValidatorException
- {
- String field = value.toString();
- if (StringValidations.isEmptyString(field) || !StringValidations.isPassword(field))
- {
- FacesMessage msg = new FacesMessage("Must be at least 4 characters (most special characters allowed)");
- throw new ValidatorException(msg);
- }
- }
-}
View
64 src/main/java/com/ocpsoft/socialpm/validator/UsernameAvailabilityValidator.java
@@ -1,64 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.validator;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.Validator;
-import javax.faces.validator.ValidatorException;
-import javax.inject.Inject;
-
-import com.ocpsoft.socialpm.domain.NoSuchObjectException;
-import com.ocpsoft.socialpm.model.UserService;
-
-@FacesValidator("usernameAvailabilityValidator")
-public class UsernameAvailabilityValidator implements Validator
-{
- @Inject
- UserService us;
-
- @Override
- public void validate(final FacesContext context, final UIComponent component, final Object value) throws ValidatorException
- {
- String field = value.toString();
- try
- {
- us.getUserByName(field);
- FacesMessage msg = new FacesMessage("Sorry, that username is already taken. Try again.");
- throw new ValidatorException(msg);
- }
- catch (NoSuchObjectException e)
- {
- }
- }
-}
View
56 src/main/java/com/ocpsoft/socialpm/validator/UsernameValidator.java
@@ -1,56 +0,0 @@
-/**
- * This file is part of SocialPM: Agile Project Management Tools (SocialPM)
- *
- * Copyright (c)2010 Lincoln Baxter, III <lincoln@ocpsoft.com> (OcpSoft)
- *
- * If you are developing and distributing open source applications under
- * the GPL Licence, then you are free to use SocialPM under the GPL
- * License:
- *
- * SocialPM is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SocialPM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SocialPM. If not, see <http://www.gnu.org/licenses/>.
- *
- * For OEMs, ISVs, and VARs who distribute SocialPM with their products,
- * host their product online, OcpSoft provides flexible OEM commercial
- * Licences.
- *
- * Optionally, customers may choose a Commercial License. For additional
- * details, contact OcpSoft (http://ocpsoft.com)
- */
-
-package com.ocpsoft.socialpm.validator;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.Validator;
-import javax.faces.validator.ValidatorException;
-
-import com.ocpsoft.socialpm.util.StringValidations;
-
-@FacesValidator("usernameValidator")
-public class UsernameValidator implements Validator
-{
- @Override
- public void validate(final FacesContext context, final UIComponent component, final Object value) throws ValidatorException
- {
- String field = value.toString();
- if (!StringValidations.isAlphanumeric(field) || !StringValidations.minLength(4, field) || !StringValidations.maxLength(15, field))
- {
- FacesMessage msg = new FacesMessage("Must be 4 to 15 numbers and/or letters");
- throw new ValidatorException(msg);
- }
- }
-
-}
View
4 src/main/resources/META-INF/persistence.xml
@@ -12,12 +12,12 @@
<jta-data-source>java:/DefaultDS</jta-data-source>
<jta-data-source> jdbc/__default </jta-data-source>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
- -->
+ -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!-- Properties for Hibernate (default provider for JBoss AS) -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
- <property name="hibernate.ejb.interceptor" value="com.ocpsoft.data.TimestampInterceptor" />
+ <property name="hibernate.ejb.interceptor" value="com.ocpsoft.socialpm.domain.TimestampInterceptor" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true"/>
<!-- Only format when you need to debug, because it slows things down -->
View
4 src/main/webapp/WEB-INF/ejb-jar.xml
@@ -9,11 +9,11 @@
<rollback>true</rollback>
</application-exception>
<application-exception>
- <exception-class>com.ocpsoft.socialpm.exceptions.DataException</exception-class>
+ <exception-class>com.ocpsoft.socialpm.domain.DataException</exception-class>
<rollback>false</rollback>
</application-exception>
<application-exception>
- <exception-class>com.ocpsoft.socialpm.exceptions.NoSuchObjectException</exception-class>
+ <exception-class>com.ocpsoft.socialpm.domain.NoSuchObjectException</exception-class>
<rollback>false</rollback>
</application-exception>
</assembly-descriptor>
View
4 src/main/webapp/WEB-INF/pretty-config.xml
@@ -67,6 +67,10 @@
<view-id> /faces/pages/login.xhtml </view-id>
<action>#{loginBean.doLogout}</action>
</url-mapping>
+ <url-mapping id="recover">
+ <pattern value="/recover" />
+ <view-id> /faces/pages/register.xhtml </view-id>
+ </url-mapping>
<url-mapping id="register">
<pattern value="/register" />
<view-id> /faces/pages/register.xhtml </view-id>
View
2  src/main/webapp/WEB-INF/view/elements/login/loginForm.xhtml
@@ -72,7 +72,7 @@
</h:panelGroup>
<br />
<br />
- <ocp:link value="#{urlConstants.RECOVER}">Lost password?</ocp:link>
+ <ocp:link value="recover">Lost password?</ocp:link>
</h:form>
<script type="text/javascript">
View
10 src/main/webapp/WEB-INF/view/elements/mainMenu.xhtml
@@ -36,26 +36,26 @@
xmlns:tmpl="http://java.sun.com/jsf/composite/ocpsoft-jsf2-templates/liquid-blue-2col"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
- <h1><pretty:link style="color: white;" mappingId="#{urlConstants.HOME}">${sitename}</pretty:link></h1>
+ <h1><pretty:link style="color: white;" mappingId="home">${sitename}</pretty:link></h1>
<ul class="fl">
</ul>
<ul class="fr">
<h:panelGroup rendered="#{loggedInUserBean.loggedIn == 'false'}">
- <li><pretty:link mappingId="#{urlConstants.REGISTER}">register</pretty:link></li>
+ <li><pretty:link mappingId="register">register</pretty:link></li>
</h:panelGroup>
<h:panelGroup rendered="#{loggedInUserBean.loggedIn == 'false'}">
- <li><pretty:link mappingId="#{urlConstants.LOGIN}">log in</pretty:link></li>
+ <li><pretty:link mappingId="login">log in</pretty:link></li>
</h:panelGroup>
<h:panelGroup rendered="#{loggedInUserBean.loggedIn == 'true'}">
<li>
- <pretty:link mappingId="#{urlConstants.LOGOUT}">
+ <pretty:link mappingId="logout">
log out [#{loggedInUserBean.user.username}]
</pretty:link>
</li>
<li>
- <pretty:link mappingId="#{urlConstants.USER_PROFILE}">
+ <pretty:link mappingId="userProfile">
<f:param value="#{loggedInUserBean.user.username}" />
<h:outputText value="profile" />
</pretty:link>
View
5 src/main/webapp/WEB-INF/view/templates/socialpm.xhtml
@@ -33,6 +33,7 @@
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:ocp="http://java.sun.com/jsf/composite/ocpcommon"
xmlns:tmpl="http://java.sun.com/jsf/composite/ocpsoft-jsf2-templates/liquid-blue-2col"
xmlns:ui="http://java.sun.com/jsf/facelets">
@@ -51,11 +52,11 @@
<a href="#">privacy</a>
<a href="#{applicationConfig.blogUrl}"> blog</a>
<a href="#"> about</a>
- <h:link outcome="terms"> terms</h:link>
+ <a href="#"> terms</a>
<a href="http://ocpsoft.com"> [&copy; ocpsoft.com]</a>
</ui:define>
- <ui:define name="messages"> </ui:define>
+ <ui:define name="messages"> <ocp:messages id="TPLmessages"/> </ui:define>
<ui:define name="menubar">
<ui:include src="/WEB-INF/view/elements/mainMenu.xhtml" />
View
27 src/main/webapp/pages/profile/userAccount.xhtml
@@ -6,9 +6,7 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ocp="http://java.sun.com/jsf/composite/ocpcommon"
xmlns:pretty="http://ocpsoft.com/prettyfaces"
- xmlns:socialpm="http://java.sun.com/jsf/composite/socialpm"
- xmlns:s="http://jboss.org/seam/faces"
- xmlns:a="http://java.sun.com/jsf/composite/ajax">
+ xmlns:s="http://jboss.org/seam/faces">
<ui:composition template="/WEB-INF/view/templates/socialpm.xhtml">
<ui:param name="title"
@@ -20,7 +18,7 @@
</ui:define>
<ui:define name="header-ul">
- <li><pretty:link mappingId="#{urlConstants.USER_PROFILE}">
+ <li><pretty:link mappingId="userProfile">
<f:param value="#{loggedInUserBean.user.username}" />
Back to profile
</pretty:link></li>
@@ -47,7 +45,7 @@
<h:inputSecret id="password" required="false"
value="#{userAccountBean.newPassword}">
<f:validator validatorId="passwordValidator" />
- <f:ajax execute="@this" render="passwordError" />
+ <f:ajax execute="@this" render="passwordError" />
</h:inputSecret>
<br />
<br />
@@ -58,14 +56,16 @@
<br />
<h:inputSecret id="passwordConfirm" required="false"
validator="#{userAccountBean.validatePasswordsMatch}">
- <f:validator validatorId="passwordValidator" />
- <f:ajax execute="password @this validatePasswords" render=":TPLmessages:TPLmessages passwordError passwordConfirmError" />
+ <f:validator validatorId="passwordValidator" />
+ <f:ajax execute="password @this validatePasswords"
+ render=":TPLmessages passwordError passwordConfirmError" />
</h:inputSecret>
<br />
- <br />
-
- <s:validateForm id="validatePasswords" validatorId="passwordConfirm" fields="password1=password password2=passwordConfirm"/>
-
+ <br />
+
+ <s:validateForm id="validatePasswords" validatorId="passwordConfirm"
+ fields="password1=password password2=passwordConfirm" />
+
<label for="oldpassword"><h:outputText
value="Old Password *: " /> <ocp:message id="oldPasswordError"
@@ -75,13 +75,14 @@
value="#{userAccountBean.oldPassword}">
<f:validator validatorId="currentUserPasswordValidator" />
</h:inputSecret>
-
+
<ocp:separator />
<span class="faded">* required</span>
<br />
<br />
<h:commandButton value="Save" action="#{userAccountBean.save}" />
- <h:commandButton immediate="true" value="Cancel" action="#{userAccountBean.cancel}" />
+ <h:commandButton immediate="true" value="Cancel"
+ action="#{userAccountBean.cancel}" />
</f:validateBean>
</h:form>
</ui:define>
View
10 src/main/webapp/pages/profile/userProfile.xhtml
@@ -5,9 +5,7 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ocp="http://java.sun.com/jsf/composite/ocpcommon"
- xmlns:pretty="http://ocpsoft.com/prettyfaces"
- xmlns:socialpm="http://java.sun.com/jsf/composite/socialpm"
- xmlns:a="http://java.sun.com/jsf/composite/ajax">
+ xmlns:pretty="http://ocpsoft.com/prettyfaces">
<ui:composition template="/WEB-INF/view/templates/socialpm.xhtml">
<ui:param name="title"
@@ -22,7 +20,7 @@
</ui:define>
<ui:define name="header-ul">
- <li><pretty:link mappingId="#{urlConstants.USER_ACCOUNT}" rendered="#{userProfileBean.editMode}">
+ <li><pretty:link mappingId="pretty:userAccount" rendered="#{userProfileBean.editMode}">
Change email &amp; password
</pretty:link></li>
</ui:define>
@@ -46,7 +44,7 @@
<f:convertDateTime />
</h:outputText> <span class="faded"> -- <h:outputText
value="#{userProfileBean.user.createdOn}">
- <f:converter converterId="prettyTimeConverter" />
+ <f:converter converterId="com.ocpsoft.PrettyTimeConverter" />
</h:outputText></span></td>
</tr>
<tr>
@@ -55,7 +53,7 @@
rendered="#{userProfileBean.editMode or !userProfileBean.user.profile.emailSecret}" />
- <pretty:link
rendered="#{userProfileBean.editMode or !userProfileBean.user.profile.emailSecret}"
- mappingId="#{urlConstants.USER_ACCOUNT}">
+ mappingId="userAccount">
change
</pretty:link></td>
</tr>
View
1  src/main/webapp/resources/ocpcommon/messages.xhtml
@@ -36,7 +36,6 @@
<composite:interface>
<composite:attribute name="globalOnly" required="false" type="Boolean" />
- <composite:attribute name="name" required="false" type="Boolean" />
</composite:interface>
<composite:implementation>
View
56 src/test/java/com/ocpsoft/socialpm/model/UserServiceTest.java
@@ -22,10 +22,13 @@
package com.ocpsoft.socialpm.model;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.util.List;
+
import javax.inject.Inject;
import org.jboss.arquillian.api.Deployment;
@@ -40,6 +43,7 @@
import org.junit.runner.RunWith;
import com.ocpsoft.socialpm.domain.DomainRoot;
+import com.ocpsoft.socialpm.domain.feed.FeedEvent;
import com.ocpsoft.socialpm.domain.user.User;
import com.ocpsoft.socialpm.util.UtilRoot;
@@ -51,20 +55,24 @@
@Run(RunModeType.IN_CONTAINER)
public class UserServiceTest
{
+
@Deployment
public static JavaArchive createTestArchive()
{
return ShrinkWrap.create(JavaArchive.class, "test.jar")
- .addPackages(true, DomainRoot.class.getPackage())
- .addPackages(true, UtilRoot.class.getPackage())
- .addPackages(true, ModelRoot.class.getPackage())
- .addManifestResource("test-beans.xml", ArchivePaths.create("beans.xml"))
- .addManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));
+ .addPackages(true, DomainRoot.class.getPackage())
+ .addPackages(true, UtilRoot.class.getPackage())
+ .addPackages(true, ModelRoot.class.getPackage())
+ .addManifestResource("test-beans.xml", ArchivePaths.create("beans.xml"))
+ .addManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));
}
@Inject
private UserService us;
+ @Inject
+ private FeedService fs;
+ private static final String PASSWORD = "testpass";
private static int count = 0;
private User user;
@@ -73,10 +81,9 @@ public void incrementUser()
{
this.user = new User();
user.setUsername("test" + count);
- user.setPassword("testpass");
+ user.setPassword(PASSWORD);
user.setEmail("test" + count + "@ocpsoft.com");
count++;
- System.out.println("New username:" + user);
}
@Test
@@ -90,6 +97,13 @@ public void testCanCreateNewUser() throws Exception
assertFalse(user.isAccountLocked());
assertNotNull(user.getRegistrationKey());
assertNotNull(key);
+ }
+
+ @Test
+ public void testCanVerifyNewUser() throws Exception
+ {
+ String key = us.registerUser(user);
+ assertFalse(user.isVerified());
User verified = us.verifyUser(key);
assertTrue(verified.isVerified());
@@ -104,4 +118,32 @@ public void testDisablingUser() throws Exception
User u = us.getUserByName(user.getUsername());
assertFalse(u.isEnabled());
}
+
+ @Test
+ public void testReEnablingUser() throws Exception
+ {
+ us.registerUser(user);
+ us.disableAccount(user);
+ assertFalse(user.isEnabled());
+
+ us.enableAccount(user, PASSWORD);
+ User u = us.getUserByName(user.getUsername());
+ assertTrue(u.isEnabled());
+ }
+
+ @Test
+ public void testPasswordIs() throws Exception
+ {
+ us.registerUser(user);
+ assertTrue(us.passwordIs(user, PASSWORD));
+ assertFalse(us.passwordIs(user, "nottherightpass"));
+ }
+
+ public void testRegisterUserFiresFeedEvent() throws Exception
+ {
+ us.registerUser(user);
+ List<FeedEvent> events = fs.listByUser(user, 0, 0);
+ assertEquals(1, events.size());
+ assertEquals(user, events.get(0).getUser());
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.