mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-04-02 02:10:20 +02:00
improve repository manager and handler relation
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
/**
|
||||
* 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,
|
||||
@@ -13,7 +13,7 @@
|
||||
* 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
|
||||
@@ -24,22 +24,29 @@
|
||||
* 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;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <T>
|
||||
* @param <E>
|
||||
*/
|
||||
public interface HandlerBase<T extends TypedObject, E extends Exception> extends Initable, Closeable
|
||||
public interface HandlerBase<T extends TypedObject, E extends Exception>
|
||||
extends Initable, Closeable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -74,37 +81,4 @@ public interface HandlerBase<T extends TypedObject, E extends Exception> extends
|
||||
* @throws IOException
|
||||
*/
|
||||
public void modify(T object) throws E, IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param object
|
||||
*
|
||||
* @throws E
|
||||
* @throws IOException
|
||||
*/
|
||||
public void refresh(T object) throws E, IOException;
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public T get(String id);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<T> getAll();
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ package sonia.scm;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
@@ -48,6 +50,38 @@ public interface Manager<T extends TypedObject, E extends Exception>
|
||||
extends HandlerBase<T, E>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param object
|
||||
*
|
||||
* @throws E
|
||||
* @throws IOException
|
||||
*/
|
||||
public void refresh(T object) throws E, IOException;
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public T get(String id);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<T> getAll();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -49,7 +49,6 @@ import java.io.IOException;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
@@ -212,18 +211,6 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*/
|
||||
protected void initNewRepository(Repository repository)
|
||||
{
|
||||
repository.setId(UUID.randomUUID().toString());
|
||||
repository.setCreationDate(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -47,15 +47,8 @@ import sonia.scm.util.IOUtil;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -70,7 +63,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_REPOSITORY = "repositories";
|
||||
|
||||
/** Field description */
|
||||
/** the logger for AbstractSimpleRepositoryHandler */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(AbstractSimpleRepositoryHandler.class);
|
||||
|
||||
@@ -89,8 +82,6 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
public void create(Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
initNewRepository(repository);
|
||||
|
||||
File directory = getDirectory(repository);
|
||||
|
||||
if (directory.exists())
|
||||
@@ -100,8 +91,6 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
|
||||
create(repository, directory);
|
||||
postCreate(repository, directory);
|
||||
repository.setType(getType().getName());
|
||||
storeRepositoryConfig(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,16 +125,14 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
File directory = getDirectory(repository);
|
||||
File repositoryFile = getRepositoryFile(repository);
|
||||
|
||||
if (directory.exists() && repositoryFile.exists())
|
||||
if (directory.exists())
|
||||
{
|
||||
IOUtil.delete(directory);
|
||||
IOUtil.delete(repositoryFile);
|
||||
}
|
||||
else
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
throw new RepositoryException("repository does not exists");
|
||||
logger.warn("repository {} not found", repository);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +146,6 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
super.init(context);
|
||||
createConfigDirectory(context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,125 +193,12 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
public void modify(Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
Repository old = get(repository.getId());
|
||||
|
||||
if (old.getName().equals(repository.getName()))
|
||||
{
|
||||
storeRepositoryConfig(repository);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RepositoryException(
|
||||
"the name of a repository could not changed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void refresh(Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
Repository fresh = get(repository.getId());
|
||||
|
||||
fresh.copyProperties(repository);
|
||||
// nothing todo
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Repository get(String id)
|
||||
{
|
||||
File repositoryFile = getRepositoryFile(id);
|
||||
Repository repository = null;
|
||||
|
||||
if (repositoryFile.exists())
|
||||
{
|
||||
repository = getRepositoryFromConfig(repositoryFile);
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<Repository> getAll()
|
||||
{
|
||||
List<Repository> repositories = new ArrayList<Repository>();
|
||||
File[] repositoryFiles = configDirectory.listFiles(new FilenameFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File dir, String name)
|
||||
{
|
||||
return name.endsWith(".xml");
|
||||
}
|
||||
});
|
||||
|
||||
for (File repositoryFile : repositoryFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
Repository repository = getRepositoryFromConfig(repositoryFile);
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
repositories.add(repository);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
return repositories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryname
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Repository getByName(String repositoryname)
|
||||
{
|
||||
Repository repository = null;
|
||||
|
||||
for (Repository r : getAll())
|
||||
{
|
||||
if (r.getName().equals(repositoryname))
|
||||
{
|
||||
repository = r;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -395,24 +268,6 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
protected void createConfigDirectory(SCMContextProvider context)
|
||||
{
|
||||
configDirectory =
|
||||
new File(baseDirectory,
|
||||
"config".concat(File.separator).concat(getType().getName()));
|
||||
|
||||
if (!configDirectory.exists() &&!configDirectory.mkdirs())
|
||||
{
|
||||
throw new ConfigurationException("could not create config directory");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -436,75 +291,4 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
*/
|
||||
protected void postCreate(Repository repository, File directory)
|
||||
throws IOException, RepositoryException {}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*/
|
||||
protected void storeRepositoryConfig(Repository repository)
|
||||
{
|
||||
JAXB.marshal(repository, getRepositoryFile(repository));
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryFile
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected Repository getRepositoryFromConfig(File repositoryFile)
|
||||
{
|
||||
Repository repository = JAXB.unmarshal(repositoryFile, Repository.class);
|
||||
File directory = getDirectory(repository);
|
||||
|
||||
if (!directory.exists())
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("could not find repository ".concat(repository.getName()));
|
||||
}
|
||||
|
||||
repository = null;
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private File getRepositoryFile(String id)
|
||||
{
|
||||
return new File(configDirectory, id.concat(".xml"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private File getRepositoryFile(Repository repository)
|
||||
{
|
||||
return getRepositoryFile(repository.getId());
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private File configDirectory;
|
||||
}
|
||||
|
||||
@@ -63,10 +63,11 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(propOrder =
|
||||
{
|
||||
"id", "type", "name", "contact", "description", "creationDate", "url",
|
||||
"permissions"
|
||||
"id", "type", "name", "contact", "description", "creationDate",
|
||||
"lastModified", "url", "permissions"
|
||||
})
|
||||
public class Repository implements TypedObject, Validateable, Serializable
|
||||
public class Repository
|
||||
implements TypedObject, Validateable, Cloneable, Serializable
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -126,6 +127,29 @@ public class Repository implements TypedObject, Validateable, Serializable
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Repository clone()
|
||||
{
|
||||
Repository repository = null;
|
||||
|
||||
try
|
||||
{
|
||||
repository = (Repository) super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException ex)
|
||||
{
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -142,6 +166,22 @@ public class Repository implements TypedObject, Validateable, Serializable
|
||||
repository.setUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder("Repository{type=");
|
||||
|
||||
buffer.append(type).append(", name=").append(name).append("}");
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -188,6 +228,17 @@ public class Repository implements TypedObject, Validateable, Serializable
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Long getLastModified()
|
||||
{
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -293,6 +344,17 @@ public class Repository implements TypedObject, Validateable, Serializable
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param lastModified
|
||||
*/
|
||||
public void setLastModified(long lastModified)
|
||||
{
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -352,6 +414,10 @@ public class Repository implements TypedObject, Validateable, Serializable
|
||||
/** Field description */
|
||||
private String id;
|
||||
|
||||
/** Field description */
|
||||
@XmlJavaTypeAdapter(XmlTimestampDateAdapter.class)
|
||||
private Long lastModified;
|
||||
|
||||
/** Field description */
|
||||
private String name;
|
||||
|
||||
|
||||
@@ -47,6 +47,17 @@ public interface RepositoryManager
|
||||
ListenerSupport<RepositoryListener>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Repository get(String type, String name);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
/**
|
||||
* 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.repository.xml;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.xml.XmlTimestampDateAdapter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
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;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class XmlRepositoryDatabase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*/
|
||||
public void add(Repository repository)
|
||||
{
|
||||
repositoryMap.put(createKey(repository), repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(String type, String name)
|
||||
{
|
||||
return repositoryMap.containsKey(createKey(type, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(String id)
|
||||
{
|
||||
return get(id) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(Repository repository)
|
||||
{
|
||||
return repositoryMap.containsKey(createKey(repository));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*/
|
||||
public void remove(Repository repository)
|
||||
{
|
||||
repositoryMap.remove(createKey(repository));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<Repository> values()
|
||||
{
|
||||
return repositoryMap.values();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Repository get(String type, String name)
|
||||
{
|
||||
return repositoryMap.get(createKey(type, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Repository get(String id)
|
||||
{
|
||||
Repository repository = null;
|
||||
|
||||
for (Repository r : values())
|
||||
{
|
||||
if (r.getId().equals(id))
|
||||
{
|
||||
repository = r;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static String createKey(String type, String name)
|
||||
{
|
||||
return type.concat(":").concat(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static String createKey(Repository repository)
|
||||
{
|
||||
return createKey(repository.getType(), repository.getName());
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlJavaTypeAdapter(XmlTimestampDateAdapter.class)
|
||||
private Long creationTime;
|
||||
|
||||
/** Field description */
|
||||
@XmlJavaTypeAdapter(XmlTimestampDateAdapter.class)
|
||||
private Long lastModified;
|
||||
|
||||
/** Field description */
|
||||
@XmlJavaTypeAdapter(XmlRepositoryMapAdapter.class)
|
||||
@XmlElement(name = "repositories")
|
||||
private Map<String, Repository> repositoryMap = new LinkedHashMap<String,
|
||||
Repository>();
|
||||
}
|
||||
@@ -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.repository.xml;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
//~--- 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 = "repositories")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class XmlRepositoryList implements Iterable<Repository>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public XmlRepositoryList() {}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param repositoryMap
|
||||
*/
|
||||
public XmlRepositoryList(Map<String, Repository> repositoryMap)
|
||||
{
|
||||
this.repositories = new LinkedList<Repository>(repositoryMap.values());
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Repository> iterator()
|
||||
{
|
||||
return repositories.iterator();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LinkedList<Repository> getRepositories()
|
||||
{
|
||||
return repositories;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositories
|
||||
*/
|
||||
public void setRepositories(LinkedList<Repository> repositories)
|
||||
{
|
||||
this.repositories = repositories;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@XmlElement(name = "repository")
|
||||
private LinkedList<Repository> repositories;
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
package sonia.scm.repository.xml;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
@@ -46,32 +46,45 @@ import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.repository.AbstractRepositoryManager;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryAllreadyExistExeption;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RepositoryHandler;
|
||||
import sonia.scm.repository.RepositoryHandlerNotFoundException;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String DATABASEFILE =
|
||||
"config".concat(File.separator).concat("repositories.xml");
|
||||
|
||||
/** Field description */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(BasicRepositoryManager.class);
|
||||
LoggerFactory.getLogger(XmlRepositoryManager.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
@@ -82,10 +95,10 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
* @param handlerSet
|
||||
*/
|
||||
@Inject
|
||||
public BasicRepositoryManager(Set<RepositoryHandler> handlerSet)
|
||||
public XmlRepositoryManager(Set<RepositoryHandler> handlerSet)
|
||||
{
|
||||
handlerMap = new HashMap<String, RepositoryHandler>();
|
||||
types = new ArrayList<Type>();
|
||||
types = new HashSet<Type>();
|
||||
|
||||
for (RepositoryHandler handler : handlerSet)
|
||||
{
|
||||
@@ -130,7 +143,22 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
}
|
||||
|
||||
AssertUtil.assertIsValid(repository);
|
||||
|
||||
if (repositoryDB.contains(repository))
|
||||
{
|
||||
throw new RepositoryAllreadyExistExeption();
|
||||
}
|
||||
|
||||
repository.setId(UUID.randomUUID().toString());
|
||||
repository.setCreationDate(System.currentTimeMillis());
|
||||
getHandler(repository).create(repository);
|
||||
|
||||
synchronized (XmlRepositoryDatabase.class)
|
||||
{
|
||||
repositoryDB.add(repository);
|
||||
storeDB();
|
||||
}
|
||||
|
||||
fireEvent(repository, HandlerEvent.CREATE);
|
||||
}
|
||||
|
||||
@@ -153,7 +181,22 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
repository.getType());
|
||||
}
|
||||
|
||||
getHandler(repository).delete(repository);
|
||||
if (repositoryDB.contains(repository))
|
||||
{
|
||||
getHandler(repository).delete(repository);
|
||||
|
||||
synchronized (XmlRepositoryDatabase.class)
|
||||
{
|
||||
repositoryDB.remove(repository);
|
||||
storeDB();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RepositoryException(
|
||||
"repository ".concat(repository.getName()).concat(" not found"));
|
||||
}
|
||||
|
||||
fireEvent(repository, HandlerEvent.DELETE);
|
||||
}
|
||||
|
||||
@@ -164,7 +207,23 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
* @param context
|
||||
*/
|
||||
@Override
|
||||
public void init(SCMContextProvider context) {}
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
File directory = context.getBaseDirectory();
|
||||
|
||||
repositoryDBFile = new File(directory, DATABASEFILE);
|
||||
|
||||
if (repositoryDBFile.exists())
|
||||
{
|
||||
loadDB();
|
||||
}
|
||||
else
|
||||
{
|
||||
IOUtil.mkdirs(repositoryDBFile.getParentFile());
|
||||
repositoryDB = new XmlRepositoryDatabase();
|
||||
repositoryDB.setCreationTime(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -186,7 +245,25 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
}
|
||||
|
||||
AssertUtil.assertIsValid(repository);
|
||||
getHandler(repository).modify(repository);
|
||||
|
||||
if (repositoryDB.contains(repository))
|
||||
{
|
||||
getHandler(repository).modify(repository);
|
||||
repository.setLastModified(System.currentTimeMillis());
|
||||
|
||||
synchronized (XmlRepositoryDatabase.class)
|
||||
{
|
||||
repositoryDB.remove(repository);
|
||||
repositoryDB.add(repository.clone());
|
||||
storeDB();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RepositoryException(
|
||||
"repository ".concat(repository.getName()).concat(" not found"));
|
||||
}
|
||||
|
||||
fireEvent(repository, HandlerEvent.MODIFY);
|
||||
}
|
||||
|
||||
@@ -203,7 +280,20 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
public void refresh(Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
getHandler(repository).refresh(repository);
|
||||
AssertUtil.assertIsNotNull(repository);
|
||||
|
||||
Repository fresh = repositoryDB.get(repository.getType(),
|
||||
repository.getName());
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
repository.copyProperties(fresh);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RepositoryException(
|
||||
"repository ".concat(repository.getName()).concat(" not found"));
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -212,7 +302,6 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
@@ -220,19 +309,38 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
@Override
|
||||
public Repository get(String id)
|
||||
{
|
||||
Repository repository = null;
|
||||
AssertUtil.assertIsNotEmpty(id);
|
||||
|
||||
for (RepositoryHandler handler : handlerMap.values())
|
||||
Repository repository = repositoryDB.get(id);
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
if (handler.isConfigured())
|
||||
{
|
||||
repository = handler.get(id);
|
||||
repository = repository.clone();
|
||||
}
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Repository get(String type, String name)
|
||||
{
|
||||
AssertUtil.assertIsNotEmpty(type);
|
||||
AssertUtil.assertIsNotEmpty(name);
|
||||
|
||||
Repository repository = repositoryDB.get(type, name);
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
repository = repository.clone();
|
||||
}
|
||||
|
||||
return repository;
|
||||
@@ -247,29 +355,11 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
@Override
|
||||
public Collection<Repository> getAll()
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
LinkedList<Repository> repositories = new LinkedList<Repository>();
|
||||
|
||||
for (Repository repository : repositoryDB.values())
|
||||
{
|
||||
logger.debug("fetch all repositories");
|
||||
}
|
||||
|
||||
Set<Repository> repositories = new HashSet<Repository>();
|
||||
|
||||
for (RepositoryHandler handler : handlerMap.values())
|
||||
{
|
||||
if (handler.isConfigured())
|
||||
{
|
||||
Collection<Repository> handlerRepositories = handler.getAll();
|
||||
|
||||
if (handlerRepositories != null)
|
||||
{
|
||||
repositories.addAll(handlerRepositories);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("fetched {} repositories", repositories.size());
|
||||
repositories.add(repository.clone());
|
||||
}
|
||||
|
||||
return repositories;
|
||||
@@ -334,6 +424,26 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
types.add(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
private void loadDB()
|
||||
{
|
||||
repositoryDB = JAXB.unmarshal(repositoryDBFile,
|
||||
XmlRepositoryDatabase.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
private void storeDB()
|
||||
{
|
||||
repositoryDB.setLastModified(System.currentTimeMillis());
|
||||
JAXB.marshal(repositoryDB, repositoryDBFile);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -372,5 +482,11 @@ public class BasicRepositoryManager extends AbstractRepositoryManager
|
||||
private Map<String, RepositoryHandler> handlerMap;
|
||||
|
||||
/** Field description */
|
||||
private List<Type> types;
|
||||
private XmlRepositoryDatabase repositoryDB;
|
||||
|
||||
/** Field description */
|
||||
private File repositoryDBFile;
|
||||
|
||||
/** Field description */
|
||||
private Set<Type> types;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* 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.repository.xml;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class XmlRepositoryMapAdapter
|
||||
extends XmlAdapter<XmlRepositoryList, Map<String, Repository>>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryMap
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public XmlRepositoryList marshal(Map<String, Repository> repositoryMap)
|
||||
throws Exception
|
||||
{
|
||||
return new XmlRepositoryList(repositoryMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositories
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Repository> unmarshal(XmlRepositoryList repositories)
|
||||
throws Exception
|
||||
{
|
||||
Map<String, Repository> repositoryMap = new LinkedHashMap<String,
|
||||
Repository>();
|
||||
|
||||
for (Repository repository : repositories)
|
||||
{
|
||||
repositoryMap.put(XmlRepositoryDatabase.createKey(repository),
|
||||
repository);
|
||||
}
|
||||
|
||||
return repositoryMap;
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ public class BasicUserManager implements UserManager
|
||||
logger.info("refresh user {} of type {}", user.getName(), user.getType());
|
||||
}
|
||||
|
||||
getHandler(user).refresh(user);
|
||||
// getHandler(user).refresh(user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,8 +250,8 @@ public class BasicUserManager implements UserManager
|
||||
{
|
||||
if (handler.isConfigured())
|
||||
{
|
||||
user = handler.get(id);
|
||||
|
||||
// user = handler.get(id);
|
||||
if (user != null)
|
||||
{
|
||||
break;
|
||||
@@ -278,19 +278,20 @@ public class BasicUserManager implements UserManager
|
||||
|
||||
Set<User> repositories = new HashSet<User>();
|
||||
|
||||
for (UserHandler handler : handlerMap.values())
|
||||
{
|
||||
if (handler.isConfigured())
|
||||
{
|
||||
Collection<User> handlerRepositories = handler.getAll();
|
||||
|
||||
if (handlerRepositories != null)
|
||||
{
|
||||
repositories.addAll(handlerRepositories);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* for (UserHandler handler : handlerMap.values())
|
||||
* {
|
||||
* if (handler.isConfigured())
|
||||
* {
|
||||
* Collection<User> handlerRepositories = handler.getAll();
|
||||
*
|
||||
* if (handlerRepositories != null)
|
||||
* {
|
||||
* repositories.addAll(handlerRepositories);
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("fetched {} users", repositories.size());
|
||||
|
||||
@@ -117,6 +117,22 @@ public class User
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
public void copyProperties(User user)
|
||||
{
|
||||
user.setAdmin(admin);
|
||||
user.setDisplayName(displayName);
|
||||
user.setMail(mail);
|
||||
user.setName(name);
|
||||
user.setPassword(password);
|
||||
user.setType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -225,7 +225,6 @@ public class XmlUserHandler implements UserHandler
|
||||
* @throws IOException
|
||||
* @throws UserException
|
||||
*/
|
||||
@Override
|
||||
public void refresh(User user) throws UserException, IOException
|
||||
{
|
||||
User fresh = userDB.get(user.getName());
|
||||
@@ -235,10 +234,7 @@ public class XmlUserHandler implements UserHandler
|
||||
throw new UserException("user does not exists");
|
||||
}
|
||||
|
||||
user.setDisplayName(fresh.getDisplayName());
|
||||
user.setMail(fresh.getMail());
|
||||
user.setPassword(fresh.getPassword());
|
||||
user.setType(TYPE_NAME);
|
||||
fresh.copyProperties(user);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -251,7 +247,6 @@ public class XmlUserHandler implements UserHandler
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public User get(String id)
|
||||
{
|
||||
User user = userDB.get(id);
|
||||
@@ -270,7 +265,6 @@ public class XmlUserHandler implements UserHandler
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<User> getAll()
|
||||
{
|
||||
LinkedList<User> users = new LinkedList<User>();
|
||||
|
||||
Reference in New Issue
Block a user