Java tutorial
/** * Copyright (C) 2008-2010, Squale Project - http://www.squale.org * * This file is part of Squale. * * Squale is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or any later version. * * Squale 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 Lesser General Public License * along with Squale. If not, see <http://www.gnu.org/licenses/>. */ //Source file: D:\\cc_views\\squale_v0_0_act_M400843\\squale\\src\\squaleCommon\\src\\org\\squale\\squalecommon\\enterpriselayer\\businessobject\\component\\ApplicationBO.java package org.squale.squalecommon.enterpriselayer.businessobject.component; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.commons.lang.builder.ToStringBuilder; import org.squale.squalecommon.enterpriselayer.businessobject.UnexpectedRelationException; import org.squale.squalecommon.enterpriselayer.businessobject.access.UserAccessBO; import org.squale.squalecommon.enterpriselayer.businessobject.config.AuditFrequencyBO; import org.squale.squalecommon.enterpriselayer.businessobject.config.ServeurBO; import org.squale.squalecommon.enterpriselayer.businessobject.profile.UserBO; import org.squale.squalecommon.enterpriselayer.businessobject.sharedrepository.ApplicationExportBO; /** * Reprsente une application * * @author m400842 * @hibernate.subclass lazy="true" discriminator-value="Application" */ public class ApplicationBO extends AbstractComplexComponentBO { /** * Generated UID */ private static final long serialVersionUID = 3347680528535207656L; /** * L'application est en cration (non valide) */ public static final int IN_CREATION = 0; /** * L'application est valide. */ public static final int VALIDATED = 1; /** * L'application est supprime. */ public static final int DELETED = 2; /** * Frquence d'audit en nombre de jour */ private int mAuditFrequency; /** * Rgle de purge */ private int mResultsStorageOptions; /** * indique si l'application tait dja en production au moment de sa cration dans SQUALE */ private boolean mIsInProduction; /** * Indique si l'application a t dvelopp en externe */ private boolean mExternalDev; /** * Contient le status du projet (non valid, en cration, ...) */ private int mStatus; /** * Date de dernire modification du projet */ private Date mLastUpdate; /** * Nom du dernier utilisateur ayant modifi l'application */ private String mLastUser; /** * Contient le nom des trois derniers accs utilisateur non administrateur Squale */ private List mUserAccesses = new ArrayList(); /** * Site sur lequel les sources sont hberges (Valbonne, ...) */ private ServeurBO mServeurBO; /** * Application publique */ private boolean mPublic; /** * List of all source code recovering termination task. Attribute use when the source code recovering optimization * is enabled */ private HashSet<Object> sourceCodeTerminationTask; /** * Does the quality approach started at the beginning of the project */ private boolean mIsQualityApproachOnStart; /** * Does the application is in its initial development phase */ private boolean mIsInInitialDev; /** * Global cost of the application */ private int globalCost; /** * The development cost of the application in its initial development phase. Only available when the project is on * its initial development phase. */ private int devCost; /** * The last export of the application */ private ApplicationExportBO lastExport; /** * Set of user which have rights for this application */ private Set<UserBO> userList = new HashSet<UserBO>(); /** * Instancie un nouveau composant. * * @param pName Nom du composant. * @roseuid 42AFF0B3011B */ public ApplicationBO(final String pName) { super(); setName(pName); } /** * Access method for the mAuditFrequency property. * * @return the current value of the mAuditFrequency property * @hibernate.property name="auditFrequency" column="AuditFrequency" type="integer" length="10" not-null="false" * unique="false" insert="true" update="true" * @roseuid 42BACECB0380 */ public int getAuditFrequency() { return mAuditFrequency; } /** * Sets the value of the mAuditFrequency property. * * @param pAuditFrequency the new value of the mAuditFrequency property * @roseuid 42BACECB0381 */ public void setAuditFrequency(int pAuditFrequency) { mAuditFrequency = pAuditFrequency; } /** * Access method for the mResultsStorageOptions property. * * @return the current value of the mResultsStorageOptions property * @hibernate.property column="ResultsStorageOptions" type="integer" length="10" not-null="false" unique="false" * insert="true" update="true" name="resultsStorageOptions" * @roseuid 42BACECB0383 */ public int getResultsStorageOptions() { return mResultsStorageOptions; } /** * Sets the value of the mResultsStorageOptions property. * * @param pResultsStorageOptions the new value of the mResultsStorageOptions property * @roseuid 42BACECB0390 */ public void setResultsStorageOptions(int pResultsStorageOptions) { mResultsStorageOptions = pResultsStorageOptions; } /** * Retourne le statut de l'application * * @return the mStatus property is true * @hibernate.property name="status" column="Status" type="integer" length="10" unique="false" insert="true" * update="true" * @roseuid 42CAA72C0133 */ public int getStatus() { return mStatus; } /** * Sets the value of the mStatus property. * * @param pStatus le status du projet * @roseuid 42CAA72C020E */ public void setStatus(int pStatus) { mStatus = pStatus; } /** * Constructeur par dfaut. * * @roseuid 42CB9778032A */ public ApplicationBO() { super(); sourceCodeTerminationTask = new HashSet<Object>(); } /** * Constructeur complet. * * @param pName nom du composant * @param pAuditFrequency frquence d'audit * @param pResultsStorageOptions options de stockage des rsultats * @param pStatus projet valid ou non * @param pAudits Collection des audits * @param pChildren Collection d'enfants * @param pSiteId le site de l'application * @param pExternalDev le boolen indiquant si c'est un dveloppement externe * @param pIsInProduction un boolen indiquant si l'application tait dj en production au moment de sa cration * dans SQUALE * @throws UnexpectedRelationException si la relation ne peut etre ajout * @roseuid 42CB9779000D */ public ApplicationBO(String pName, int pAuditFrequency, int pResultsStorageOptions, int pStatus, Collection pAudits, Collection pChildren, long pSiteId, boolean pExternalDev, boolean pIsInProduction) throws UnexpectedRelationException { super(pName, pChildren, null); mAuditFrequency = pAuditFrequency; mResultsStorageOptions = pResultsStorageOptions; mStatus = pStatus; mAudits = pAudits; mServeurBO = new ServeurBO(); mServeurBO.setServeurId(pSiteId); mExternalDev = pExternalDev; mIsInProduction = pIsInProduction; sourceCodeTerminationTask = new HashSet<Object>(); } /** * Rcupre l'attribut mPublic * * @return projet est-il public * @hibernate.property column="PublicApplication" type="boolean" unique="false" insert="true" update="true" * name="public" */ public boolean getPublic() { return mPublic; } /** * Affecte pPublic l'attribut mPublic. * * @param pPublic projet est-il publique * @roseuid 42CE36C203DF */ public void setPublic(boolean pPublic) { mPublic = pPublic; } /** * Rcupre l'attribut mLastUpdate * * @return la date de dernire modification. * @hibernate.property name="lastUpdate" column="LastUpdate" type="timestamp" not-null="false" unique="false" * insert="true" update="true" */ public Date getLastUpdate() { return mLastUpdate; } /** * Modifie l'attribut mLastUpdate * * @param pDate la date */ public void setLastUpdate(Date pDate) { mLastUpdate = pDate; } /** * Affecte la date courante l'attribut mLastUpdate */ public void setLastUpdate() { Calendar cal = new GregorianCalendar(); mLastUpdate = cal.getTime(); } /** * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object pObj) { boolean ret = false; if (pObj instanceof ApplicationBO) { ApplicationBO appli = (ApplicationBO) pObj; ret = (getName() != null) && (appli.getName() != null) && getName().equals(appli.getName()) && (getStatus() == appli.getStatus()); } return ret; } /** * @see java.lang.Object#hashCode() */ public int hashCode() { return getName() == null ? super.hashCode() : getName().hashCode(); } /** * @see java.lang.Object#toString() */ public String toString() { ToStringBuilder stringBuilder = new ToStringBuilder(this); stringBuilder.append("Name", mName); return stringBuilder.toString(); } /** * @return le boolen indiquant si le dev a t fait en externe ou pas * @hibernate.property column="EXTERNAL_DEV" type="boolean" unique="false" insert="true" update="true" * name="externalDev" */ public boolean getExternalDev() { return mExternalDev; } /** * @return le boolen indiquant si l'application tait dj en production au moment de sa cration dans squale * @hibernate.property name="inProduction" column="IN_PRODUCTION" type="boolean" unique="false" insert="true" * update="true" */ public boolean getInProduction() { return mIsInProduction; } /** * @param pExternal le boolen indiquant si le dev a t fait en externe */ public void setExternalDev(boolean pExternal) { mExternalDev = pExternal; } /** * @param pInProduction le boolen indiquant si l'application tait dj en production au */ public void setInProduction(boolean pInProduction) { mIsInProduction = pInProduction; } /** * @return le dernier utilisateur ayant modifi l'application * @hibernate.property column="lastUser" type="string" length="1024" unique="false" insert="true" update="true" * name="lastUser" */ public String getLastUser() { return mLastUser; } /** * @param pUser le dernier utilisateur ayant modifi l'application */ public void setLastUser(String pUser) { mLastUser = pUser; } /** * Retourne le serveur de l'application * * @return le serveur de l'application * @hibernate.many-to-one column="Serveur" * class="org.squale.squalecommon.enterpriselayer.businessobject.config.ServeurBO" * not-null="false" insert="true" update="true" cascade="none" outer-join="auto" */ // name="serveurBO" public ServeurBO getServeurBO() { return mServeurBO; } /** * Modifie le serveur de l'application * * @param pServeurBO le serveur de l'application */ public void setServeurBO(ServeurBO pServeurBO) { mServeurBO = pServeurBO; } /** * @return les 3 derniers accs utilisateur * @hibernate.list table="UserAccess" cascade="all" lazy="false" * @hibernate.key column="ApplicationId" * @hibernate.index column="AccessIndex" type="long" length="19" * @hibernate.one-to-many class="org.squale.squalecommon.enterpriselayer.businessobject.access.UserAccessBO" */ public List getUserAccesses() { return mUserAccesses; } /** * @param pAccessBOs les accs utilisateur */ public void setUserAccesses(List pAccessBOs) { mUserAccesses = pAccessBOs; } /** * Ajoute un accs en supprimant le dernier lment du tableau et en dcalant les autres lements afin d'ajouter * l'accs en premier * * @param pAccessBO l'accs ajouter * @param maxSize le nombre limite d'accs conserver */ public void addUserAccess(UserAccessBO pAccessBO, int maxSize) { // On n'ajoute l'lment seulement si il n'existe pas dj if (!mUserAccesses.contains(pAccessBO)) { // On affecte l'application pAccessBO.setApplication(this); // On ajoute l'lment en dbut de liste mUserAccesses.add(0, pAccessBO); // Si la taille max est atteinte, on supprime le dernier lment int stackSize = mUserAccesses.size(); if (stackSize > maxSize) { mUserAccesses.remove(stackSize - 1); } } } /** * @param pFrequencies les frquences max autorises * @return true si on a chang la frquence de l'application */ public boolean changeFrequency(Collection pFrequencies) { boolean hasChanged = false; if (null != mUserAccesses && mUserAccesses.size() > 0) { // Le dernier accs utilisateur Date lastAccess = ((UserAccessBO) mUserAccesses.get(0)).getDate(); // On fait ensuite une recherche sur le nombre de jours max des frquences // afin de vrifier que la frquence de l'application respecte la configuration SQUALIX int nbDaysMax = findFrequency(lastAccess, pFrequencies); // On vrifie la frquence (> 0 car peut avoir que des audits de jalon) if (mAuditFrequency > 0 && mAuditFrequency < nbDaysMax) { // On change la frquence setAuditFrequency(nbDaysMax); hasChanged = true; } } return hasChanged; } /** * @param lastAccess le dernier accs utilisateur * @param pFrequencies les frquences. La collection ne doit pas tre nulle ni vide. * @return la frquence */ private int findFrequency(Date lastAccess, Collection pFrequencies) { // initialisation int frequencyToChange = -1; // Si la frquence ne doit pas tre change, on retourne -1 // constantes pour le calcul du nombre de jour final int HOURS_IN_DAY = 24; final int MINUTES_IN_HOUR = 60; final int SECONDS_IN_MINUTE = 60; final int MILLI_IN_SECOND = 1000; // On rcupre le nombre de jours depuis le dernier accs Calendar today = Calendar.getInstance(); Calendar access = Calendar.getInstance(); access.setTime(lastAccess); // on compte le nombre de jours qui sparent les deux dates int nbDays = new Long((today.getTimeInMillis() - access.getTimeInMillis()) / HOURS_IN_DAY / MINUTES_IN_HOUR / SECONDS_IN_MINUTE / MILLI_IN_SECOND).intValue(); // On va crer la liste des frquences tries par nombre de jours List frequencies = new ArrayList(pFrequencies); Collections.sort(frequencies); AuditFrequencyBO frequency = null; frequency = (AuditFrequencyBO) frequencies.get(0); int curFreq = frequency.getDays(); if (curFreq < nbDays) { boolean found = false; // Tant qu'on a pas trouv la limite on itre for (int i = 1; !found && i < frequencies.size(); i++) { frequency = (AuditFrequencyBO) frequencies.get(i); if (frequency.getDays() < nbDays) { curFreq = frequency.getFrequency(); } else { found = true; } } frequencyToChange = curFreq; } return frequencyToChange; } /** * {@inheritDoc} * * @see org.squale.squalecommon.enterpriselayer.businessobject.component.AbstractComponentBO#accept(org.squale.squalecommon.enterpriselayer.businessobject.component.ComponentVisitor, * java.lang.Object) */ public Object accept(ComponentVisitor pVisitor, Object pArgument) { return pVisitor.visit(this, pArgument); } /** * Get the list of source code recovering termination task which should be done at the end of the audit * * @return The list of source code recovering termination task */ public HashSet<Object> getSourceCodeTerminationTask() { return sourceCodeTerminationTask; } /** * Set the list of source code recovering termination task which should be done at the end of the audit * * @param pSourceCodeTerminationTask The list of source code recovering termination task */ public void setSourceCodeTerminationTask(HashSet<Object> pSourceCodeTerminationTask) { sourceCodeTerminationTask = pSourceCodeTerminationTask; } /** * Getter method for the attribute isQualityApproachOnStart * * @hibernate.property name="qualityApproachOnStart" column="QualityApproachOnStart" type="boolean" unique="false" * insert="true" update="true" * @return true if the quality approach started at the beginning of the project */ public boolean getQualityApproachOnStart() { return (mIsQualityApproachOnStart); } /** * Setter method for the attribute isQualityApproachOnStart * * @param pIsQualityApproachOnStart The new value for the attribute isQualityApproachOnStart */ public void setQualityApproachOnStart(boolean pIsQualityApproachOnStart) { mIsQualityApproachOnStart = pIsQualityApproachOnStart; } /** * Getter method for the attribute isInInitialDev * * @hibernate.property name="inInitialDev" column="InInitialDev" type="boolean" unique="false" insert="true" * update="true" * @return true if the application is in initial development phase */ public boolean getInInitialDev() { return mIsInInitialDev; } /** * Setter method for the attribute isInInitialDev * * @param pIsInInitialDev The new value for the attribute isInInitialDev */ public void setInInitialDev(boolean pIsInInitialDev) { mIsInInitialDev = pIsInInitialDev; } /** * Getter method for the attribute globalCost * * @hibernate.property name="globalCost" column="GlobalCost" type="integer" length="10" unique="false" insert="true" * update="true" * @return The global cost of the application */ public int getGlobalCost() { return globalCost; } /** * Setter method for the attribute globalCost * * @param pGlobalCost The new value for globalcost attribute */ public void setGlobalCost(int pGlobalCost) { globalCost = pGlobalCost; } /** * Getter method for the attribute devCost * * @hibernate.property name="devCost" column="DevCost" type="integer" length="10" unique="false" insert="true" * update="true" * @return the development cost of the application */ public int getDevCost() { return devCost; } /** * Setter method for the devCost attribute * * @param pDevCost The new value for the devcost attribute */ public void setDevCost(int pDevCost) { devCost = pDevCost; } /** * Getter for the attribute last export * * @hibernate.one-to-one * class="org.squale.squalecommon.enterpriselayer.businessobject.sharedrepository.ApplicationExportBO" * property-ref="application" cascade="all" lazy="no-proxy" fetch="join" * @return information on the last export */ public ApplicationExportBO getLastExport() { return lastExport; } /** * Setter for the attribut last export * * @param pLastExport The new information set of the last export */ public void setLastExport(ApplicationExportBO pLastExport) { lastExport = pLastExport; } /** * Verify if the audit given in argument is obsolete. The audit should be an audit of the current application * * @param audit The audit to verify * @return true if the audit is obsolete */ public boolean isAuditObsolete(AuditBO audit) { boolean obsolete = true; Calendar cal = GregorianCalendar.getInstance(); Calendar calAuditDate = GregorianCalendar.getInstance(); calAuditDate.setTime(audit.getRealBeginningDate()); calAuditDate.add(Calendar.DATE, mResultsStorageOptions); if (calAuditDate.after(cal)) { obsolete = false; } return obsolete; } /** * Getter method for the attribute userList * * @return the list of user which have rights for this application * @hibernate.set cascade="none" lazy="true" table="User_Rights" inverse="true" sort="unsorted" * @hibernate.key column="ApplicationId" * @hibernate.many-to-many class="org.squale.squalecommon.enterpriselayer.businessobject.profile.UserBO" * column="UserId" outer-join="auto" */ public Set<UserBO> getUserList() { return userList; } /** * Setter method for the attribute userList * * @param pUserList The new list of user which have rights for the application */ public void setUserList(Set<UserBO> pUserList) { userList = pUserList; } }