mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 19:45:51 +01:00
added XmlGroupManager
This commit is contained in:
@@ -38,6 +38,7 @@ package sonia.scm.group;
|
|||||||
import sonia.scm.TypedObject;
|
import sonia.scm.TypedObject;
|
||||||
import sonia.scm.Validateable;
|
import sonia.scm.Validateable;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
import sonia.scm.xml.XmlTimestampDateAdapter;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ import java.util.List;
|
|||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -174,6 +176,99 @@ public class Group
|
|||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param group
|
||||||
|
*/
|
||||||
|
public void copyProperties(Group group)
|
||||||
|
{
|
||||||
|
group.setName(name);
|
||||||
|
group.setMembers(members);
|
||||||
|
group.setType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param obj
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Group other = (Group) obj;
|
||||||
|
|
||||||
|
if ((this.creationDate != other.creationDate)
|
||||||
|
&& ((this.creationDate == null)
|
||||||
|
||!this.creationDate.equals(other.creationDate)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((this.members != other.members)
|
||||||
|
&& ((this.members == null) ||!this.members.equals(other.members)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((this.name == null)
|
||||||
|
? (other.name != null)
|
||||||
|
: !this.name.equals(other.name))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((this.type == null)
|
||||||
|
? (other.type != null)
|
||||||
|
: !this.type.equals(other.type))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int hash = 5;
|
||||||
|
|
||||||
|
hash = 89 * hash + ((this.creationDate != null)
|
||||||
|
? this.creationDate.hashCode()
|
||||||
|
: 0);
|
||||||
|
hash = 89 * hash + ((this.members != null)
|
||||||
|
? this.members.hashCode()
|
||||||
|
: 0);
|
||||||
|
hash = 89 * hash + ((this.name != null)
|
||||||
|
? this.name.hashCode()
|
||||||
|
: 0);
|
||||||
|
hash = 89 * hash + ((this.type != null)
|
||||||
|
? this.type.hashCode()
|
||||||
|
: 0);
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -232,6 +327,17 @@ public class Group
|
|||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Long getCreationDate()
|
||||||
|
{
|
||||||
|
return creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -285,6 +391,17 @@ public class Group
|
|||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param creationDate
|
||||||
|
*/
|
||||||
|
public void setCreationDate(Long creationDate)
|
||||||
|
{
|
||||||
|
this.creationDate = creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -320,6 +437,10 @@ public class Group
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlJavaTypeAdapter(XmlTimestampDateAdapter.class)
|
||||||
|
private Long creationDate;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private List<String> members;
|
private List<String> members;
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ import sonia.scm.config.ScmConfiguration;
|
|||||||
import sonia.scm.filter.GZipFilter;
|
import sonia.scm.filter.GZipFilter;
|
||||||
import sonia.scm.filter.SSLFilter;
|
import sonia.scm.filter.SSLFilter;
|
||||||
import sonia.scm.filter.SecurityFilter;
|
import sonia.scm.filter.SecurityFilter;
|
||||||
|
import sonia.scm.group.GroupManager;
|
||||||
|
import sonia.scm.group.xml.XmlGroupManager;
|
||||||
import sonia.scm.plugin.DefaultPluginManager;
|
import sonia.scm.plugin.DefaultPluginManager;
|
||||||
import sonia.scm.plugin.Plugin;
|
import sonia.scm.plugin.Plugin;
|
||||||
import sonia.scm.plugin.PluginLoader;
|
import sonia.scm.plugin.PluginLoader;
|
||||||
@@ -181,6 +183,7 @@ public class ScmServletModule extends ServletModule
|
|||||||
// BasicRepositoryManager.class);
|
// BasicRepositoryManager.class);
|
||||||
bind(RepositoryManager.class).to(XmlRepositoryManager.class);
|
bind(RepositoryManager.class).to(XmlRepositoryManager.class);
|
||||||
bind(UserManager.class).to(XmlUserManager.class);
|
bind(UserManager.class).to(XmlUserManager.class);
|
||||||
|
bind(GroupManager.class).to(XmlGroupManager.class);
|
||||||
|
|
||||||
// filter(PATTERN_RESTAPI).through(LoggingFilter.class);
|
// filter(PATTERN_RESTAPI).through(LoggingFilter.class);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,180 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, Sebastian Sdorra
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from this
|
||||||
|
* software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.group.xml;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.group.Group;
|
||||||
|
import sonia.scm.xml.XmlTimestampDateAdapter;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class XmlGroupDatabase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param group
|
||||||
|
*/
|
||||||
|
public void add(Group group)
|
||||||
|
{
|
||||||
|
groupMap.put(group.getName(), group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param groupname
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean contains(String groupname)
|
||||||
|
{
|
||||||
|
return groupMap.containsKey(groupname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param groupname
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Group remove(String groupname)
|
||||||
|
{
|
||||||
|
return groupMap.remove(groupname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Collection<Group> values()
|
||||||
|
{
|
||||||
|
return groupMap.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param groupname
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Group get(String groupname)
|
||||||
|
{
|
||||||
|
return groupMap.get(groupname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public long getCreationTime()
|
||||||
|
{
|
||||||
|
return creationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public long getLastModified()
|
||||||
|
{
|
||||||
|
return lastModified;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param creationTime
|
||||||
|
*/
|
||||||
|
public void setCreationTime(long creationTime)
|
||||||
|
{
|
||||||
|
this.creationTime = creationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param lastModified
|
||||||
|
*/
|
||||||
|
public void setLastModified(long lastModified)
|
||||||
|
{
|
||||||
|
this.lastModified = lastModified;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlJavaTypeAdapter(XmlTimestampDateAdapter.class)
|
||||||
|
private Long creationTime;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlJavaTypeAdapter(XmlGroupMapAdapter.class)
|
||||||
|
@XmlElement(name = "groups")
|
||||||
|
private Map<String, Group> groupMap = new LinkedHashMap<String, Group>();
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlJavaTypeAdapter(XmlTimestampDateAdapter.class)
|
||||||
|
private Long lastModified;
|
||||||
|
}
|
||||||
123
scm-webapp/src/main/java/sonia/scm/group/xml/XmlGroupList.java
Normal file
123
scm-webapp/src/main/java/sonia/scm/group/xml/XmlGroupList.java
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, Sebastian Sdorra
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from this
|
||||||
|
* software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.group.xml;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.group.Group;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "groups")
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public class XmlGroupList implements Iterable<Group>
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public XmlGroupList() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param groupMap
|
||||||
|
*/
|
||||||
|
public XmlGroupList(Map<String, Group> groupMap)
|
||||||
|
{
|
||||||
|
this.groups = new LinkedList<Group>(groupMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Iterator<Group> iterator()
|
||||||
|
{
|
||||||
|
return groups.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public LinkedList<Group> getGroups()
|
||||||
|
{
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param groups
|
||||||
|
*/
|
||||||
|
public void setGroups(LinkedList<Group> groups)
|
||||||
|
{
|
||||||
|
this.groups = groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "group")
|
||||||
|
private LinkedList<Group> groups;
|
||||||
|
}
|
||||||
@@ -0,0 +1,339 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, Sebastian Sdorra
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from this
|
||||||
|
* software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.group.xml;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.SCMContextProvider;
|
||||||
|
import sonia.scm.group.AbstractGroupManager;
|
||||||
|
import sonia.scm.group.Group;
|
||||||
|
import sonia.scm.group.GroupAllreadyExistExeption;
|
||||||
|
import sonia.scm.group.GroupException;
|
||||||
|
import sonia.scm.security.SecurityContext;
|
||||||
|
import sonia.scm.store.Store;
|
||||||
|
import sonia.scm.store.StoreFactory;
|
||||||
|
import sonia.scm.util.SecurityUtil;
|
||||||
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class XmlGroupManager extends AbstractGroupManager
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String STORE_NAME = "groups";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String TYPE = "xml";
|
||||||
|
|
||||||
|
/** the logger for XmlGroupManager */
|
||||||
|
private static final Logger logger =
|
||||||
|
LoggerFactory.getLogger(XmlGroupManager.class);
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param securityContextProvider
|
||||||
|
* @param storeFactory
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
public XmlGroupManager(Provider<SecurityContext> securityContextProvider,
|
||||||
|
StoreFactory storeFactory)
|
||||||
|
{
|
||||||
|
this.securityContextProvider = securityContextProvider;
|
||||||
|
this.store = storeFactory.getStore(XmlGroupDatabase.class, STORE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param group
|
||||||
|
*
|
||||||
|
* @throws GroupException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void create(Group group) throws GroupException, IOException
|
||||||
|
{
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("create group {} of type {}", group.getName(),
|
||||||
|
group.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
SecurityUtil.assertIsAdmin(securityContextProvider);
|
||||||
|
|
||||||
|
if (groupDB.contains(group.getName()))
|
||||||
|
{
|
||||||
|
throw new GroupAllreadyExistExeption();
|
||||||
|
}
|
||||||
|
|
||||||
|
String type = group.getType();
|
||||||
|
|
||||||
|
if (Util.isEmpty(type))
|
||||||
|
{
|
||||||
|
group.setType(TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
group.setCreationDate(System.currentTimeMillis());
|
||||||
|
|
||||||
|
synchronized (XmlGroupManager.class)
|
||||||
|
{
|
||||||
|
groupDB.add(group.clone());
|
||||||
|
storeDB();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param group
|
||||||
|
*
|
||||||
|
* @throws GroupException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delete(Group group) throws GroupException, IOException
|
||||||
|
{
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("delete group {} of type {}", group.getName(),
|
||||||
|
group.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
SecurityUtil.assertIsAdmin(securityContextProvider);
|
||||||
|
|
||||||
|
String name = group.getName();
|
||||||
|
|
||||||
|
if (groupDB.contains(name))
|
||||||
|
{
|
||||||
|
synchronized (XmlGroupManager.class)
|
||||||
|
{
|
||||||
|
groupDB.remove(name);
|
||||||
|
storeDB();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new GroupException("user does not exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void init(SCMContextProvider context)
|
||||||
|
{
|
||||||
|
if (groupDB == null)
|
||||||
|
{
|
||||||
|
groupDB = new XmlGroupDatabase();
|
||||||
|
groupDB.setCreationTime(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param group
|
||||||
|
*
|
||||||
|
* @throws GroupException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void modify(Group group) throws GroupException, IOException
|
||||||
|
{
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("modify group {} of type {}", group.getName(),
|
||||||
|
group.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
SecurityUtil.assertIsAdmin(securityContextProvider);
|
||||||
|
|
||||||
|
String name = group.getName();
|
||||||
|
|
||||||
|
if (groupDB.contains(name))
|
||||||
|
{
|
||||||
|
synchronized (XmlGroupManager.class)
|
||||||
|
{
|
||||||
|
groupDB.remove(name);
|
||||||
|
groupDB.add(group.clone());
|
||||||
|
storeDB();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new GroupException("group does not exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param group
|
||||||
|
*
|
||||||
|
* @throws GroupException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void refresh(Group group) throws GroupException, IOException
|
||||||
|
{
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("refresh group {} of type {}", group.getName(),
|
||||||
|
group.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
SecurityUtil.assertIsAdmin(securityContextProvider);
|
||||||
|
|
||||||
|
Group fresh = groupDB.get(group.getName());
|
||||||
|
|
||||||
|
if (fresh == null)
|
||||||
|
{
|
||||||
|
throw new GroupException("group does not exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
fresh.copyProperties(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Group get(String id)
|
||||||
|
{
|
||||||
|
Group group = groupDB.get(id);
|
||||||
|
|
||||||
|
if (group != null)
|
||||||
|
{
|
||||||
|
group = group.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Collection<Group> getAll()
|
||||||
|
{
|
||||||
|
SecurityUtil.assertIsAdmin(securityContextProvider);
|
||||||
|
|
||||||
|
LinkedList<Group> groups = new LinkedList<Group>();
|
||||||
|
|
||||||
|
for (Group group : groupDB.values())
|
||||||
|
{
|
||||||
|
groups.add(group.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void storeDB()
|
||||||
|
{
|
||||||
|
groupDB.setLastModified(System.currentTimeMillis());
|
||||||
|
store.set(groupDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private XmlGroupDatabase groupDB;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Provider<SecurityContext> securityContextProvider;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Store<XmlGroupDatabase> store;
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, Sebastian Sdorra
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from this
|
||||||
|
* software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.group.xml;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.group.Group;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class XmlGroupMapAdapter
|
||||||
|
extends XmlAdapter<XmlGroupList, Map<String, Group>>
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param groupMap
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public XmlGroupList marshal(Map<String, Group> groupMap) throws Exception
|
||||||
|
{
|
||||||
|
return new XmlGroupList(groupMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param groups
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Group> unmarshal(XmlGroupList groups) throws Exception
|
||||||
|
{
|
||||||
|
Map<String, Group> groupMap = new LinkedHashMap<String, Group>();
|
||||||
|
|
||||||
|
for (Group group : groups)
|
||||||
|
{
|
||||||
|
groupMap.put(group.getName(), group);
|
||||||
|
}
|
||||||
|
|
||||||
|
return groupMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user