Commit 6fd4a3bd authored by OUGHDI's avatar OUGHDI
Browse files

RELEASER-16 : Check if a site exists when trying to add it

parent 864e004a
......@@ -124,4 +124,23 @@ public interface ISiteDAO
* @return the list which contains the data of all the site objects
*/
List<Site> selectByCluster( int nClusterId, Plugin plugin );
/**
* Find if site is already exist
*
* @param siteName
* The site Name
*
* @param artifactId
* The artifactId of the site
*
* @param scmurl
* The site's scm url
*
* @param plugin
* The plugin
*
* @return the cluster name which contains the existing site
*/
String searchDuplicateSite( String siteName, String artifactId, String scmUrl, Plugin plugin );
}
......@@ -58,6 +58,8 @@ public final class SiteDAO implements ISiteDAO
private static final String SQL_QUERY_SELECT_BY_CLUSTER = "SELECT a.id_site, a.name, a.description, a.artifact_id, a.id_cluster, b.name, a.scm_url, a.jira_key,a.is_theme "
+ " FROM releaser_site a , releaser_cluster b WHERE a.id_cluster = b.id_cluster AND a.id_cluster = ?";
private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_site FROM releaser_site";
private static final String SQL_QUERY_SELECT_SEARCH_DUPLICATE_SITE = "SELECT b.name, a.id_site FROM releaser_site a LEFT OUTER JOIN releaser_cluster b"
+ " ON a.id_cluster = b.id_cluster WHERE a.artifact_id = ? OR a.name = ? OR a.scm_url = ?";
/**
* Generates a new primary key
......@@ -274,4 +276,28 @@ public final class SiteDAO implements ISiteDAO
daoUtil.free( );
return siteList;
}
/**
* {@inheritDoc }
*/
@Override
public String searchDuplicateSite( String siteName, String artifactId, String scmUrl, Plugin plugin )
{
String clusterName = null;
DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_SEARCH_DUPLICATE_SITE, plugin );
daoUtil.setNString( 1, artifactId );
daoUtil.setNString( 2, siteName );
daoUtil.setNString( 3, scmUrl );
daoUtil.executeQuery( );
while ( daoUtil.next( ) )
{
int nIndex = 1;
if ( daoUtil != null && daoUtil.getString( 1 ) != null )
clusterName = daoUtil.getString( 1 );
}
daoUtil.free( );
return clusterName;
}
}
......@@ -148,5 +148,25 @@ public final class SiteHome
{
return _dao.selectByCluster( nClusterId, _plugin );
}
/**
* Search if the site is already exist
*
* @param siteName
* The site name
*
* @param artifactId
* The site artifacteId
*
* @param scmUrl
* The site sources url
*
* @return the the cluster name if site exists or null otherwise
*/
public static String findDuplicateSite( String siteName, String artifactId, String scmUrl )
{
return _dao.searchDuplicateSite( siteName, artifactId, scmUrl, _plugin );
}
}
......@@ -146,6 +146,7 @@ message.releleaseVersionAlreadyExist=Release version <b>{0}</b> already exist.
message.twitterMessage=Le composant <b>{0}<b> est dsormais disponible en version <b>{1}<b>.
message.wrongPomParentSiteVersion=la version du POM parent du site doit \u00e9tre <b>{0}<b>, lors de la release le POM sera mise jour avec cette version
message.accessDenied=Access denied
message.siteAlreadyExist=This site is already exist
# JSR 303 constraint validator messages
validation.releaseruser.SvnSiteAccountLogin.notEmpty=Login Svn
......
......@@ -67,9 +67,6 @@ modify_site.labelJiraKey.help=Identifiant JIRA du site
modify_site.labelIsTheme=D\u00e9finir comme Theme
modify_site.labelIsTheme.help=D\u00e9finir comme Theme
message.confirmRemoveSite=Etes vous sur de vouloir supprimer ce site ?
prepare_site_release.labelTagInformation=Ajouter une information sur le Tag
prepare_site_release.labelTagInformation.help=Ajouter une information sur le Tag
......@@ -122,8 +119,6 @@ modify_cluster.labelName.help=Nom du cluster
modify_cluster.labelDescription=Description
modify_cluster.labelDescription.help=Description du cluster
message.confirmRemoveCluster=Etes vous sur de vouloir supprimer ce cluster ?
# JSR 303 constraint validator messages
validation.cluster.Name.notEmpty=Le champ Nom ne doit pas \u00eatre vide. Veuillez le remplir SVP.
validation.cluster.Name.size=Le champ Nom ne doit pas contenir plus de 50 caract\u00e8res.
......@@ -150,7 +145,10 @@ message.moreRecentVersionAvailable=Une version <b>{0}</b> plus r\u00e9cente est
message.releleaseVersionAlreadyExist=La version release <b>{0}</b> est disponible.
message.twitterMessage=Le composant <b>{0}<b> est d\u00e9sormais disponible en version <b>{1}<b>.
message.wrongPomParentSiteVersion=la version du POM parent du site doit \u00e9tre <b>{0}<b>, lors de la release le POM sera mise à jour avec cette version
message.confirmRemoveSite=Etes vous sur de vouloir supprimer ce site ?
message.confirmRemoveCluster=Etes vous sur de vouloir supprimer ce cluster ?
message.accessDenied=Accès refusé
message.siteAlreadyExist=Ce site existe déjà
# JSR 303 constraint validator messages
validation.releaseruser.SvnSiteAccountLogin.notEmpty=Login Svn
......
......@@ -69,6 +69,7 @@ import fr.paris.lutece.plugins.releaser.util.version.VersionParsingException;
import fr.paris.lutece.portal.business.user.AdminUser;
import fr.paris.lutece.portal.service.datastore.DatastoreService;
import fr.paris.lutece.portal.service.i18n.I18nService;
import fr.paris.lutece.portal.service.plugin.Plugin;
import fr.paris.lutece.portal.service.rbac.RBACService;
import fr.paris.lutece.portal.service.util.AppException;
import fr.paris.lutece.portal.service.util.AppLogService;
......@@ -807,5 +808,14 @@ public class SiteService
return bAuthorized;
}
public static boolean IsSiteAlreadyExist ( String siteName, String artifactId, String scmUrl )
{
String clusterName = SiteHome.findDuplicateSite( siteName, artifactId, scmUrl );
if (clusterName != null)
return true;
return false;
}
}
......@@ -49,6 +49,7 @@ import fr.paris.lutece.plugins.releaser.util.ReleaserUtils;
import fr.paris.lutece.portal.business.user.AdminUser;
import fr.paris.lutece.portal.service.admin.AccessDeniedException;
import fr.paris.lutece.portal.service.admin.AdminUserService;
import fr.paris.lutece.portal.service.i18n.I18nService;
import fr.paris.lutece.portal.service.message.AdminMessage;
import fr.paris.lutece.portal.service.message.AdminMessageService;
import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
......@@ -94,6 +95,7 @@ public class ClusterJspBean extends ManageSitesJspBean
// Messages
private static final String MESSAGE_ACCESS_DENIED = "releaser.message.accesDenied";
private static final String MESSAGE_SITE_ALREADY_EXIST = "releaser.message.siteAlreadyExist";
// Markers
private static final String MARK_CLUSTER_LIST = "cluster_list";
......@@ -473,6 +475,13 @@ public class ClusterJspBean extends ManageSitesJspBean
{
return redirectView( request, VIEW_CREATE_SITE );
}
if ( SiteService.IsSiteAlreadyExist(_site.getName(), _site.getArtifactId(), _site.getScmUrl()) )
{
String errorMessage = I18nService.getLocalizedString( MESSAGE_SITE_ALREADY_EXIST, getLocale() );
addError(errorMessage);
return redirectView( request, VIEW_CREATE_SITE );
}
SiteHome.create( _site );
addInfo( INFO_SITE_CREATED, getLocale( ) );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment