mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
make date format configurable
This commit is contained in:
90
scm-webapp/src/main/java/sonia/scm/ScmClientConfig.java
Normal file
90
scm-webapp/src/main/java/sonia/scm/ScmClientConfig.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class ScmClientConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public ScmClientConfig() {}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param dateFormat
|
||||
*/
|
||||
public ScmClientConfig(String dateFormat)
|
||||
{
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getDateFormat()
|
||||
{
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param dateFormat
|
||||
*/
|
||||
public void setDateFormat(String dateFormat)
|
||||
{
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String dateFormat;
|
||||
}
|
||||
@@ -71,19 +71,33 @@ public class ScmState
|
||||
* @param provider
|
||||
* @param securityContext
|
||||
* @param repositoryTypes
|
||||
* @param clientConfig
|
||||
*/
|
||||
public ScmState(SCMContextProvider provider,
|
||||
WebSecurityContext securityContext,
|
||||
Collection<Type> repositoryTypes)
|
||||
Collection<Type> repositoryTypes,
|
||||
ScmClientConfig clientConfig)
|
||||
{
|
||||
this.version = provider.getVersion();
|
||||
this.user = securityContext.getUser();
|
||||
this.groups = securityContext.getGroups();
|
||||
this.repositoryTypes = repositoryTypes;
|
||||
this.clientConfig = clientConfig;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ScmClientConfig getClientConfig()
|
||||
{
|
||||
return clientConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -141,6 +155,17 @@ public class ScmState
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param clientConfig
|
||||
*/
|
||||
public void setClientConfig(ScmClientConfig clientConfig)
|
||||
{
|
||||
this.clientConfig = clientConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -198,6 +223,9 @@ public class ScmState
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private ScmClientConfig clientConfig;
|
||||
|
||||
/** Field description */
|
||||
private Collection<String> groups;
|
||||
|
||||
|
||||
@@ -44,7 +44,9 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.ScmClientConfig;
|
||||
import sonia.scm.ScmState;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.web.security.WebSecurityContext;
|
||||
@@ -85,16 +87,18 @@ public class AuthenticationResource
|
||||
*
|
||||
*
|
||||
* @param contextProvider
|
||||
* @param configuration
|
||||
* @param repositoryManger
|
||||
* @param securityContextProvider
|
||||
*/
|
||||
@Inject
|
||||
public AuthenticationResource(
|
||||
SCMContextProvider contextProvider,
|
||||
SCMContextProvider contextProvider, ScmConfiguration configuration,
|
||||
RepositoryManager repositoryManger,
|
||||
Provider<WebSecurityContext> securityContextProvider)
|
||||
{
|
||||
this.contextProvider = contextProvider;
|
||||
this.configuration = configuration;
|
||||
this.repositoryManger = repositoryManger;
|
||||
this.securityContextProvider = securityContextProvider;
|
||||
}
|
||||
@@ -126,8 +130,7 @@ public class AuthenticationResource
|
||||
|
||||
if ((user != null) &&!SCMContext.USER_ANONYMOUS.equals(user.getName()))
|
||||
{
|
||||
state = new ScmState(contextProvider, securityContext,
|
||||
repositoryManger.getConfiguredTypes());
|
||||
state = createState(securityContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -160,8 +163,7 @@ public class AuthenticationResource
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
ScmState state = new ScmState(contextProvider, securityContext,
|
||||
repositoryManger.getConfiguredTypes());
|
||||
ScmState state = createState(securityContext);
|
||||
|
||||
resp = Response.ok(state).build();
|
||||
}
|
||||
@@ -198,8 +200,7 @@ public class AuthenticationResource
|
||||
logger.debug("return state for user {}", user.getName());
|
||||
}
|
||||
|
||||
state = new ScmState(contextProvider, securityContext,
|
||||
repositoryManger.getConfiguredTypes());
|
||||
state = createState(securityContext);
|
||||
response = Response.ok(state).build();
|
||||
}
|
||||
else
|
||||
@@ -210,8 +211,28 @@ public class AuthenticationResource
|
||||
return response;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param securityContext
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ScmState createState(WebSecurityContext securityContext)
|
||||
{
|
||||
return new ScmState(contextProvider, securityContext,
|
||||
repositoryManger.getConfiguredTypes(),
|
||||
new ScmClientConfig(configuration.getDateFormat()));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private SCMContextProvider contextProvider;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user