diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/auditview/control/AuditService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/auditview/control/AuditService.java index 3a800f2cf..c0aec2644 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/auditview/control/AuditService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/auditview/control/AuditService.java @@ -214,39 +214,4 @@ public void setResourceIdInThreadLocal(Integer resourceId) { ThreadLocalUtil.setThreadVariable(ThreadLocalUtil.KEY_RESOURCE_ID, resourceId); } - /** - * @return a list of three-element arrays, containing: - *
    - *
  1. the entity instance
  2. - *
  3. revision entity, corresponding to the revision at which the entity was modified. If no custom - * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}
  4. - *
  5. type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})
  6. - *
- */ - private List getAllRevisionsForEntity(T entity, Integer id){ - Objects.requireNonNull(entity, "Entity can not be null"); - Objects.requireNonNull(id, "Id can not be null"); - - AuditReader reader = AuditReaderFactory.get(entityManager); - Number revisionNumberOneYearAgo = getRevisionNumberOneYearAgo(reader); - - if (reader.isEntityClassAudited(entity.getClass())) { - AuditQuery query = reader.createQuery().forRevisionsOfEntity(entity.getClass(), false, true) - .add(AuditEntity.id().eq(id)) - .add(AuditEntity.revisionNumber().gt(revisionNumberOneYearAgo)) - .addOrder(AuditEntity.revisionNumber().desc()); - return (List) query.getResultList(); - } - return null; - } - - private Number getRevisionNumberOneYearAgo(AuditReader reader) { - Calendar c = Calendar.getInstance(); - c.setTime(new Date()); - int currentYear = c.get(Calendar.YEAR); - c.set(Calendar.YEAR, currentYear -1); - return reader.getRevisionNumberForDate(c.getTime()); - } - - } diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/database/control/AmwAuditReader.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/database/control/AmwAuditReader.java index bbc91c2c6..dabe3080a 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/database/control/AmwAuditReader.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/database/control/AmwAuditReader.java @@ -20,7 +20,6 @@ package ch.puzzle.itc.mobiliar.business.database.control; -import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.exception.RevisionDoesNotExistException; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/database/control/QueryUtils.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/database/control/QueryUtils.java index 89bcd0138..d625a492e 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/database/control/QueryUtils.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/database/control/QueryUtils.java @@ -31,8 +31,6 @@ import javax.persistence.Query; import javax.persistence.Table; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; - public class QueryUtils { @@ -51,7 +49,6 @@ public class QueryUtils { * @param length * - the length of the result set, no restriction if -1 * @return - * @throws GeneralDBException */ @SuppressWarnings("unchecked") public static List fetch(Class clazz, Query query, int start, int length) { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentExecuterService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentExecuterService.java index 4ecc93ad0..9733bf8a8 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentExecuterService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/control/DeploymentExecuterService.java @@ -31,7 +31,6 @@ import javax.ejb.Asynchronous; import javax.ejb.Stateless; import javax.inject.Inject; -import javax.persistence.EntityManager; import java.util.logging.Level; import java.util.logging.Logger; @@ -50,9 +49,6 @@ public class DeploymentExecuterService { @Inject private LockingService lockingService; - @Inject - private EntityManager entityManager; - @Inject private DeploymentAsynchronousExecuter deploymentAsynchronousExecuter; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/entity/CustomFilter.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/entity/CustomFilter.java index eeae62bf3..930b98222 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/entity/CustomFilter.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/entity/CustomFilter.java @@ -25,6 +25,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import lombok.Builder.Default; import lombok.Builder; import org.apache.commons.lang3.StringUtils; @@ -65,15 +66,18 @@ public class CustomFilter { @Setter @Getter + @Default private List dropDownItems = new ArrayList<>(); @Setter @Getter + @Default private Map dropDownItemsMap = new HashMap<>(); @Setter private Class enumType; + @Default private Object value = null; private Long filterIdentifikationNumber; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/scheduler/DeploymentScheduler.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/scheduler/DeploymentScheduler.java index 3b4268f6a..30aa60d81 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/scheduler/DeploymentScheduler.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploy/scheduler/DeploymentScheduler.java @@ -24,6 +24,7 @@ import ch.puzzle.itc.mobiliar.business.deploy.control.DeploymentExecuterService; import ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentEntity; import ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentFailureReason; +import ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentState; import ch.puzzle.itc.mobiliar.business.deploy.event.DeploymentEvent; import ch.puzzle.itc.mobiliar.business.generator.control.extracted.GenerationModus; import ch.puzzle.itc.mobiliar.business.shakedown.control.ShakedownTestExecuterService; @@ -126,8 +127,7 @@ public void handleDeploymentEvent(@Observes(during=TransactionPhase.AFTER_SUCCES executePreDeployments(); break; case UPDATE: - switch(event.getNewState()) { - case READY_FOR_DEPLOYMENT: + if (event.getNewState() == DeploymentState.READY_FOR_DEPLOYMENT) { if(event.getDeploymentId() != null) { deploymentExecuterService.generateConfigurationAndExecuteDeployment(event.getDeploymentId(), GenerationModus.DEPLOY); diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/boundary/DeploymentParameterBoundary.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/boundary/DeploymentParameterBoundary.java index eb9f2dcf0..471576ced 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/boundary/DeploymentParameterBoundary.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/boundary/DeploymentParameterBoundary.java @@ -37,7 +37,7 @@ import ch.puzzle.itc.mobiliar.business.deploymentparameter.entity.Key; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; import ch.puzzle.itc.mobiliar.business.security.interceptor.HasPermission; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; @Stateless public class DeploymentParameterBoundary { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/entity/DeploymentParameter.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/entity/DeploymentParameter.java index a57537e8d..56258bd63 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/entity/DeploymentParameter.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/entity/DeploymentParameter.java @@ -24,7 +24,7 @@ import ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentEntity; import lombok.Getter; import lombok.Setter; -import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.constraints.NotEmpty; import javax.persistence.*; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/entity/Key.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/entity/Key.java index 68ee2b2ce..9f9d87f08 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/entity/Key.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/deploymentparameter/entity/Key.java @@ -26,7 +26,7 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.NamedIdentifiable; import lombok.Getter; import lombok.Setter; -import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.constraints.NotEmpty; @Entity @Table(name = "TAMW_deployParamKey") diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/domain/commons/CommonDomainService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/domain/commons/CommonDomainService.java index 1ac6a249a..5be5b7747 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/domain/commons/CommonDomainService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/domain/commons/CommonDomainService.java @@ -29,7 +29,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.control.ResourceTypeProvider; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.*; import ch.puzzle.itc.mobiliar.business.security.control.PermissionService; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.exception.ResourceTypeNotFoundException; import ch.puzzle.itc.mobiliar.common.util.ApplicationServerContainer; @@ -114,7 +113,6 @@ public int compare(ResourceGroupEntity arg0, ResourceGroupEntity arg1) { * @param resourceId * @return the resource entity with the given id * @throws ResourceNotFoundException - * @throws GeneralDBException */ public ResourceEntity getResourceEntityById(int resourceId) throws ResourceNotFoundException { ResourceEntity result = null; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/control/ContextRepository.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/control/ContextRepository.java index 5cc7f9b13..88c2edcd4 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/control/ContextRepository.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/control/ContextRepository.java @@ -24,7 +24,6 @@ import ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentEntity; import ch.puzzle.itc.mobiliar.business.environment.entity.ContextEntity; import ch.puzzle.itc.mobiliar.business.utils.BaseRepository; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import javax.inject.Inject; import javax.persistence.EntityManager; @@ -45,7 +44,6 @@ public ContextEntity getContextByName(String name){ * Returns all Environments * * @return - * @throws GeneralDBException */ public List getEnvironments() { return QueryUtils.fetch(ContextEntity.class, fetchAllContexts(), 0, -1); diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/entity/ContextEntity.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/entity/ContextEntity.java index d27559ee8..d5f3c0bb8 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/entity/ContextEntity.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/entity/ContextEntity.java @@ -36,7 +36,6 @@ import org.hibernate.envers.NotAudited; import javax.persistence.*; -import java.io.Serializable; import java.util.Set; import static javax.persistence.CascadeType.MERGE; @@ -54,7 +53,7 @@ @AssociationOverride(name = "propertyDescriptors", joinTable = @JoinTable(name = "TAMW_context_propDesc", joinColumns = @JoinColumn(name="TAMW_CONTEXT_ID", referencedColumnName="ID"))), @AssociationOverride(name = "templates", joinTable = @JoinTable(name = "TAMW_context_tmplDesc", joinColumns = @JoinColumn(name="TAMW_CONTEXT_ID", referencedColumnName="ID"))) }) -public class ContextEntity extends AbstractContext implements Serializable { +public class ContextEntity extends AbstractContext { public static final String LOAD_CONTEXT_BY_NAME_QUERY_NAME = "loadContextByName"; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/entity/ContextTypeEntity.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/entity/ContextTypeEntity.java index 2ddeacb96..9fd4b0aca 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/entity/ContextTypeEntity.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/environment/entity/ContextTypeEntity.java @@ -20,14 +20,12 @@ package ch.puzzle.itc.mobiliar.business.environment.entity; -import ch.puzzle.itc.mobiliar.business.utils.Identifiable; import lombok.Getter; import lombok.Setter; import org.hibernate.annotations.NamedQuery; import org.hibernate.envers.Audited; import javax.persistence.*; -import java.io.Serializable; import java.util.Set; import static javax.persistence.CascadeType.ALL; @@ -46,7 +44,7 @@ @AssociationOverride(name="propertyDescriptors", joinTable=@JoinTable(name="TAMW_contextType_propDesc", joinColumns = @JoinColumn(name="TAMW_CONTEXTTYPE_ID", referencedColumnName="ID"))), @AssociationOverride(name="templates", joinTable=@JoinTable(name="TAMW_contextType_tmplDesc", joinColumns = @JoinColumn(name="TAMW_CONTEXTTYPE_ID", referencedColumnName="ID"))) }) -public class ContextTypeEntity extends AbstractContext implements Identifiable, Serializable { +public class ContextTypeEntity extends AbstractContext { public static final String LOAD_CONTEXT_TYPE_BY_NAME_QUERY_NAME = "loadContextTypeByName"; @Getter diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/foreignable/entity/ForeignableAttributesDTO.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/foreignable/entity/ForeignableAttributesDTO.java index 1c7c519bc..1acd0d6d6 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/foreignable/entity/ForeignableAttributesDTO.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/foreignable/entity/ForeignableAttributesDTO.java @@ -21,7 +21,6 @@ package ch.puzzle.itc.mobiliar.business.foreignable.entity; -import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwner; import lombok.Getter; public class ForeignableAttributesDTO { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/function/boundary/FunctionsBoundary.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/function/boundary/FunctionsBoundary.java index 3fdf52925..dd42d5512 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/function/boundary/FunctionsBoundary.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/function/boundary/FunctionsBoundary.java @@ -39,9 +39,10 @@ import ch.puzzle.itc.mobiliar.business.security.entity.Permission; import ch.puzzle.itc.mobiliar.business.template.control.FreemarkerSyntaxValidator; import ch.puzzle.itc.mobiliar.business.template.entity.RevisionInformation; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; import ch.puzzle.itc.mobiliar.common.exception.NotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; + import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/AmwModelPreprocessExceptionHandler.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/AmwModelPreprocessExceptionHandler.java index 463658407..e65da4b70 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/AmwModelPreprocessExceptionHandler.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/AmwModelPreprocessExceptionHandler.java @@ -27,7 +27,6 @@ import ch.puzzle.itc.mobiliar.common.exception.TemplatePropertyException.CAUSE; import freemarker.core.Environment; import freemarker.template.TemplateException; -import freemarker.template.TemplateExceptionHandler; /** * Custom exception handler for freemarker that does not throw the exception and therefore template processing diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/NodeGenerationResult.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/NodeGenerationResult.java index e0e1a50b8..0f6ced576 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/NodeGenerationResult.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/NodeGenerationResult.java @@ -22,11 +22,9 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.common.exception.TemplatePropertyException; -import ch.puzzle.itc.mobiliar.common.util.ConfigurationService; import lombok.Getter; import lombok.Setter; -import java.io.File; import java.util.ArrayList; import java.util.List; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/TemplateUtils.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/TemplateUtils.java index 0e8d71089..300adefc6 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/TemplateUtils.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/TemplateUtils.java @@ -548,25 +548,6 @@ public static Map> getPropertyVal return getPropertyValues(templates, context); } - /** - * Loads all templates in a specific context - * - * @param context - * @param result - * (used for recursion, can initially be defined as null) - * @return - */ - private static Set getTemplates(ContextEntity context, Set result) { - if (result == null) { - result = new HashSet<>(); - } - getTemplatesForContext(context, result); - if (context.getParent() != null) { - result = getTemplates(context.getParent(), result); - } - return result; - } - private static Set getPropertyDescriptors(ContextEntity context, Set result) { if (result == null) { result = new HashSet<>(); @@ -578,10 +559,6 @@ private static Set getPropertyDescriptors(ContextEntit return result; } - private static void getTemplatesForContext(ContextEntity context, Set result) { - collectTemplateDescriptors(context, result); - } - private static void getPropertyDescriptorsForContext(ContextEntity context, Set result) { Set properties = context.getPropertyDescriptors(); if (properties != null) { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/BaseTemplateProcessor.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/BaseTemplateProcessor.java index 6162ea94c..74a1be66b 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/BaseTemplateProcessor.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/BaseTemplateProcessor.java @@ -35,8 +35,6 @@ import ch.puzzle.itc.mobiliar.common.exception.TemplatePropertyException; import ch.puzzle.itc.mobiliar.common.exception.TemplatePropertyException.CAUSE; -import com.google.gson.GsonBuilder; - import freemarker.cache.StringTemplateLoader; import freemarker.core.ParseException; import freemarker.template.Configuration; @@ -296,12 +294,6 @@ private void logStartTemplateGeneration(TemplateDescriptorEntity template) { log.finest("started: " + template.toString()); } - private void logBeforeException(TemplateException te, Map contextualizedMap) { - log.info("Template Fehler: "); - log.severe(te.getLocalizedMessage()); - log.severe(new GsonBuilder().setPrettyPrinting().create().toJson(contextualizedMap)); - } - private void logBeforeException(ParseException pe) { log.info("ParseException: "); log.severe(pe.getLocalizedMessage()); diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/globalfunction/control/GlobalFunctionRepository.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/globalfunction/control/GlobalFunctionRepository.java index b37fc4339..75c45032b 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/globalfunction/control/GlobalFunctionRepository.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/globalfunction/control/GlobalFunctionRepository.java @@ -20,18 +20,15 @@ package ch.puzzle.itc.mobiliar.business.globalfunction.control; -import java.util.LinkedList; import java.util.List; import javax.inject.Inject; import javax.persistence.EntityManager; -import javax.persistence.OrderBy; import javax.persistence.TypedQuery; import javax.persistence.criteria.*; import javax.persistence.criteria.CriteriaQuery; import ch.puzzle.itc.mobiliar.business.globalfunction.entity.GlobalFunctionEntity; -import org.hibernate.criterion.*; public class GlobalFunctionRepository { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/globalfunction/entity/GlobalFunctionEntity.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/globalfunction/entity/GlobalFunctionEntity.java index 4f0c478ed..d872832ca 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/globalfunction/entity/GlobalFunctionEntity.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/globalfunction/entity/GlobalFunctionEntity.java @@ -29,14 +29,13 @@ import javax.persistence.Table; import javax.persistence.TableGenerator; -import ch.puzzle.itc.mobiliar.business.utils.ValidationHelper; import lombok.Getter; import lombok.Setter; import org.hibernate.envers.Audited; import ch.puzzle.itc.mobiliar.business.database.control.Constants; -import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.constraints.NotEmpty; @Entity @Audited diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/predecessor/boundary/MaiaAmwFederationServicePredecessorHandler.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/predecessor/boundary/MaiaAmwFederationServicePredecessorHandler.java index f7abbe78b..4715d43c3 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/predecessor/boundary/MaiaAmwFederationServicePredecessorHandler.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/predecessor/boundary/MaiaAmwFederationServicePredecessorHandler.java @@ -32,7 +32,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; import ch.puzzle.itc.mobiliar.business.resourcegroup.control.CopyResourceDomainService; import ch.puzzle.itc.mobiliar.business.resourcegroup.control.CopyResourceResult; -import ch.puzzle.itc.mobiliar.business.resourcegroup.control.ResourceImportService; import ch.puzzle.itc.mobiliar.business.resourcegroup.control.ResourceRepository; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroupEntity; @@ -74,9 +73,6 @@ public class MaiaAmwFederationServicePredecessorHandler { @Inject ForeignableService foreignableService; - @Inject - private ResourceImportService resourceImportService; - @Inject private ResourceRelationService resourceRelationService; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/predecessor/entity/PredecessorResultMessage.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/predecessor/entity/PredecessorResultMessage.java index 6754dcc04..8154e3b0b 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/predecessor/entity/PredecessorResultMessage.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/predecessor/entity/PredecessorResultMessage.java @@ -21,7 +21,6 @@ package ch.puzzle.itc.mobiliar.business.predecessor.entity; import lombok.Getter; -import lombok.Setter; /** * diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/boundary/PropertyEditor.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/boundary/PropertyEditor.java index fc6e295e8..f22e121be 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/boundary/PropertyEditor.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/boundary/PropertyEditor.java @@ -49,10 +49,10 @@ import ch.puzzle.itc.mobiliar.business.security.entity.Action; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; import ch.puzzle.itc.mobiliar.business.security.interceptor.HasPermission; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.business.utils.ValidationHelper; import ch.puzzle.itc.mobiliar.common.exception.AMWException; import ch.puzzle.itc.mobiliar.common.exception.NotAuthorizedException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import ch.puzzle.itc.mobiliar.common.util.ContextNames; import javax.ejb.EJBException; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyTypeScreenDomainService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyTypeScreenDomainService.java index 0937a99ec..8d07da7e9 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyTypeScreenDomainService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyTypeScreenDomainService.java @@ -69,12 +69,11 @@ public class PropertyTypeScreenDomainService { * @throws PropertyTypeNotFoundException * @throws ElementAlreadyExistsException * @throws RenameException - * @throws GeneralDBException */ @HasPermission(permission = Permission.SAVE_SETTINGS_PROPTYPE) public void updatePropertyType(int id, String name, String validation, boolean encrypted, String propertyTypeTagsString) throws PropertyTypeNotFoundException, - ElementAlreadyExistsException, RenameException, GeneralDBException { + ElementAlreadyExistsException, RenameException { PropertyTypeEntity propertyTypeEntity = getPropertyTypeById(id); PropertyTypeEntity propertyByName = getPropertyTypeByName(name); @@ -98,12 +97,10 @@ public void updatePropertyType(int id, String name, String validation, boolean e * @param prtName * @param prtValidation * @throws ElementAlreadyExistsException - * @throws GeneralDBException */ @HasPermission(permission = Permission.ADD_PROPTYPE) public PropertyTypeEntity createPropertyTypeByNameAndVal(String prtName, - String prtValidation, boolean encrypted, String propertyTypeTagsString) throws ElementAlreadyExistsException, - GeneralDBException { + String prtValidation, boolean encrypted, String propertyTypeTagsString) throws ElementAlreadyExistsException { PropertyTypeEntity newPropertyTypeEntity = commonService.getUniquePropertyTypeByName(prtName); PropertyTypeEntity result; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyTypeService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyTypeService.java index 701863350..7c0b3e621 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyTypeService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyTypeService.java @@ -25,8 +25,6 @@ import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; import java.util.List; /** diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyValueService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyValueService.java index a6d964ca4..9b55ba0ad 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyValueService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/control/PropertyValueService.java @@ -26,8 +26,8 @@ import ch.puzzle.itc.mobiliar.business.property.entity.PropertyDescriptorEntity; import ch.puzzle.itc.mobiliar.business.property.entity.PropertyEntity; import ch.puzzle.itc.mobiliar.business.property.entity.ResourceEditProperty; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import ch.puzzle.itc.mobiliar.business.auditview.control.AuditService; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import javax.inject.Inject; import javax.persistence.EntityManager; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/entity/PropertyDescriptorEntity.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/entity/PropertyDescriptorEntity.java index 5bcf78869..987da9fc5 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/entity/PropertyDescriptorEntity.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/entity/PropertyDescriptorEntity.java @@ -26,7 +26,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.control.CopyUnit; import ch.puzzle.itc.mobiliar.business.auditview.entity.Auditable; import ch.puzzle.itc.mobiliar.business.utils.CopyHelper; -import ch.puzzle.itc.mobiliar.business.utils.Copyable; import ch.puzzle.itc.mobiliar.business.utils.Identifiable; import lombok.Getter; import lombok.Setter; @@ -47,7 +46,7 @@ @Entity @Audited @Table(name = "TAMW_propertyDescriptor") -public class PropertyDescriptorEntity implements Identifiable, Serializable, PropertyTagEntityHolder, Foreignable, Copyable, Auditable { +public class PropertyDescriptorEntity implements Identifiable, Serializable, PropertyTagEntityHolder, Foreignable, Auditable { // IMPORTANT! Whenever a new field (not relation to other entity) is added then this field must be added to foreignableFieldEquals method!!! diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/entity/PropertyTagEntityHolder.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/entity/PropertyTagEntityHolder.java index 120922390..a8e0b3c6f 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/entity/PropertyTagEntityHolder.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/property/entity/PropertyTagEntityHolder.java @@ -20,7 +20,6 @@ package ch.puzzle.itc.mobiliar.business.property.entity; -import java.util.HashSet; import java.util.List; import java.util.Set; diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/releasing/control/ReleaseMgmtPersistenceService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/releasing/control/ReleaseMgmtPersistenceService.java index 0250a5824..7cdc01cbd 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/releasing/control/ReleaseMgmtPersistenceService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/releasing/control/ReleaseMgmtPersistenceService.java @@ -22,14 +22,12 @@ import ch.puzzle.itc.mobiliar.business.releasing.entity.ReleaseEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.NoResultException; -import javax.persistence.PersistenceException; import javax.persistence.TransactionRequiredException; import javax.persistence.criteria.*; import java.util.List; @@ -116,18 +114,14 @@ public ReleaseEntity findByName(String releaseName) { * * @param entity */ - public boolean saveReleaseEntity(ReleaseEntity entity) throws GeneralDBException { - try { - if(entity.getId()==null){ - entityManager.persist(entity); - log.info("Release " + entity.getName() + " saved"); - } - else{ - entityManager.merge(entity); - log.info("Release " + entity.getName() + " updated"); - } - } catch (PersistenceException e) { - throw new GeneralDBException(e.getMessage(), e); + public boolean saveReleaseEntity(ReleaseEntity entity) { + if(entity.getId()==null){ + entityManager.persist(entity); + log.info("Release " + entity.getName() + " saved"); + } + else{ + entityManager.merge(entity); + log.info("Release " + entity.getName() + " updated"); } return true; } diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/releasing/control/ReleaseMgmtService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/releasing/control/ReleaseMgmtService.java index cbfdfed7c..c3cd19868 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/releasing/control/ReleaseMgmtService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/releasing/control/ReleaseMgmtService.java @@ -28,7 +28,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroupEntity; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; import ch.puzzle.itc.mobiliar.business.security.interceptor.HasPermission; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import javax.ejb.Stateless; @@ -102,7 +101,7 @@ public int countReleases() { * Persists the given new release. */ @HasPermission(permission = Permission.RELEASE, action = CREATE) - public boolean create(ReleaseEntity release) throws GeneralDBException { + public boolean create(ReleaseEntity release) { return persistenceService.saveReleaseEntity(release); } @@ -110,7 +109,7 @@ public boolean create(ReleaseEntity release) throws GeneralDBException { * Persists the given release - the already existing instance will be updated. */ @HasPermission(permission = Permission.RELEASE, action = UPDATE) - public boolean update(ReleaseEntity release) throws GeneralDBException { + public boolean update(ReleaseEntity release) { return persistenceService.saveReleaseEntity(release); } diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourceactivation/control/ResourceActivation.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourceactivation/control/ResourceActivation.java index 23f18ac68..b7bf987fa 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourceactivation/control/ResourceActivation.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourceactivation/control/ResourceActivation.java @@ -56,7 +56,6 @@ public class ResourceActivation { public void setResourceActivation(ResourceRelationContextEntity currentResourceRelationContext, ResourceGroupEntity resourceGroup, ResourceActivationEntity existingResourceActivation, Boolean active) { //TODO cleanup active resource activation without "inactive" in between over the whole context hierarchy. boolean alreadyDefinedOnCurrentContext; - ResourceRelationContextEntity resourceRelationContextEntity; if (existingResourceActivation != null && existingResourceActivation.getResourceRelationContext().getContext().getId() .equals(currentResourceRelationContext.getContext().getId())) { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/CopyResource.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/CopyResource.java index 86e68cb45..5e4c5852a 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/CopyResource.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/CopyResource.java @@ -48,10 +48,10 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroup; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroupEntity; import ch.puzzle.itc.mobiliar.business.security.boundary.PermissionBoundary; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; import ch.puzzle.itc.mobiliar.common.exception.NotAuthorizedException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; /** * A boundary for copy resourcess diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceGroupLocator.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceGroupLocator.java index 472cd435e..765145b9f 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceGroupLocator.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceGroupLocator.java @@ -90,7 +90,6 @@ public List getAllUserAssignableResourceGroupsByName() { * @param myAmw * @param fetchResources determines if resources fetched * @return a list of Groups - * @throws ch.puzzle.itc.mobiliar.common.exception.GeneralDBException */ public List getGroupsForType(String resourceTypeName, List myAmw, boolean fetchResources, boolean sorted) { return resourceGroupControl.getGroupsForType(resourceTypeName, myAmw, fetchResources, sorted); diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceLocator.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceLocator.java index b87bc69b0..1ba18746f 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceLocator.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/boundary/ResourceLocator.java @@ -29,8 +29,8 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroupEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceTypeEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.business.utils.ValidationHelper; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import ch.puzzle.itc.mobiliar.common.util.ConfigKey; import ch.puzzle.itc.mobiliar.common.util.ConfigurationService; @@ -182,19 +182,6 @@ public List getResourcesByGroupNameWithAllRelationsOrderedByRele return resourceRepository.getResourcesByGroupNameWithAllRelationsOrderedByRelease(groupName); } - /** - * @param name - * @param releaseName - * @return - * @throws ValidationException thrown if one of the arguments is either empty or null - */ - public ResourceEntity getResourceByNameAndReleaseWithTemplates(String name, String releaseName) - throws ValidationException { - ValidationHelper.validateNotNullOrEmptyChecked(name, releaseName); - ReleaseEntity release = releaseLocator.getReleaseByName(releaseName); - return resourceRepository.getResourceByNameAndReleaseWithTemplates(name, release); - } - /** * @return resource for id with resourceGroup and other resources */ diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupPersistenceService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupPersistenceService.java index 43c48dbe6..048e761e1 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupPersistenceService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupPersistenceService.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.logging.Logger; import javax.ejb.Stateless; import javax.inject.Inject; @@ -49,9 +48,6 @@ public class ResourceGroupPersistenceService { @Inject EntityManager entityManager; - @Inject - private Logger log; - @Inject ResourceTypeProvider resourceTypeProvider; @@ -161,7 +157,6 @@ public ResourceGroupEntity loadUniqueGroupByNameAndType(String name, Integer res * Listet Applications auf alphabetic sorted * * @return - * @throws ch.puzzle.itc.mobiliar.common.exception.GeneralDBException */ public List getAllApplicationsNotBelongingToAServer() { List allApplications = new ArrayList<>(); diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupRepository.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupRepository.java index d77c64b5d..68070f90f 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupRepository.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupRepository.java @@ -86,7 +86,6 @@ public ResourceGroupEntity getResourceGroupForCreateDeploy(Integer groupId) { * @param myAmw * @param fetchResources determines if resources fetched * @return a list of Groups - * @throws ch.puzzle.itc.mobiliar.common.exception.GeneralDBException */ public List getGroupsForType(String resourceTypeName, List myAmw, boolean fetchResources, boolean sorted) { return getGroupsForType("name", resourceTypeName, myAmw, fetchResources, sorted); diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceImportService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceImportService.java index 8e5d4a470..38d65a132 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceImportService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceImportService.java @@ -22,8 +22,6 @@ import ch.puzzle.itc.mobiliar.business.environment.entity.ContextEntity; import ch.puzzle.itc.mobiliar.business.environment.entity.GlobalContext; -import ch.puzzle.itc.mobiliar.business.property.control.PropertyDescriptorService; -import ch.puzzle.itc.mobiliar.business.property.control.PropertyValueService; import ch.puzzle.itc.mobiliar.business.releasing.entity.ReleaseEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.common.util.ConfigKey; @@ -31,7 +29,6 @@ import javax.inject.Inject; import java.util.*; -import java.util.logging.Logger; public class ResourceImportService { @@ -40,20 +37,10 @@ public class ResourceImportService { @Inject ResourceReleaseComparator resourceReleaseComparator; - @Inject - private Logger log; - - @Inject - private PropertyValueService propertyValueService; - @Inject @GlobalContext private ContextEntity globalContext; - @Inject - private PropertyDescriptorService descriptorService; - - public List getAllMinorReleasesFollowingRelease(Set allReleaseResources, ReleaseEntity release) { List followingMinorRelease = new ArrayList<>(); diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceRepository.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceRepository.java index 582df4759..58e1f78a4 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceRepository.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceRepository.java @@ -109,16 +109,6 @@ public List getResourcesByGroupNameWithRelations(String name) { .setParameter("name", name.toLowerCase()).getResultList(); } - public ResourceEntity getResourceByNameAndReleaseWithTemplates(String name, ReleaseEntity release) { - return entityManager - .createQuery( - "select r from ResourceEntity r " + - "left join fetch r.consumedMasterRelations rel " + - "left join fetch rel.slaveResource where LOWER(r.name)=:name and r.release=:release", - ResourceEntity.class) - .setParameter("name", name.toLowerCase()).setParameter("release", release).getSingleResult(); - } - public List getResourcesByGroupNameWithAllRelationsOrderedByRelease(String name) { return entityManager.createQuery( "select r from ResourceEntity r " + "left join fetch r.resourceGroup rg " diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceEntity.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceEntity.java index 18e9c93d8..791790714 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceEntity.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceEntity.java @@ -41,7 +41,6 @@ import ch.puzzle.itc.mobiliar.business.shakedown.entity.ShakedownTestEntity; import ch.puzzle.itc.mobiliar.business.softlinkRelation.entity.SoftlinkRelationEntity; import ch.puzzle.itc.mobiliar.business.utils.CopyHelper; -import ch.puzzle.itc.mobiliar.business.utils.Copyable; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.util.ApplicationServerContainer; @@ -72,7 +71,7 @@ @Table(name = "TAMW_resource") @EqualsAndHashCode(callSuper = false, of = { "id", "name", "release" }) public class ResourceEntity extends HasContexts implements Serializable, - NamedIdentifiable, Comparable, HasTypeContext, Foreignable, Copyable { + NamedIdentifiable, Comparable, HasTypeContext, Foreignable { // IMPORTANT! Whenever a new field (not relation to other entity) is added then this field must be added to foreignableFieldEquals method!!! @@ -476,9 +475,10 @@ private List getConsumedRelatedMasterResources() { * Workaround because so far softlinkrelation is a one-to-one relation * @return */ + @SuppressWarnings("unused") private Set getSoftlinkRelations() { return softlinkRelations; - } + } public void clearSoftlinkRelations() { if (softlinkRelations != null) { @@ -491,9 +491,10 @@ public void clearSoftlinkRelations() { * Workaround because so far softlinkrelation is a one-to-one relation * @param softlinkRelations */ + @SuppressWarnings("unused") private void setSoftlinkRelations(Set softlinkRelations) { this.softlinkRelations = softlinkRelations; - } + } public SoftlinkRelationEntity getSoftlinkRelation(){ // workaround because so far softlinkrelation is a one-to-one relation diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/boundary/RelationEditor.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/boundary/RelationEditor.java index 72eb610ad..6f07e8668 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/boundary/RelationEditor.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/boundary/RelationEditor.java @@ -52,10 +52,10 @@ import ch.puzzle.itc.mobiliar.business.resourcerelation.control.ResourceRelationService; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.AbstractResourceRelationEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ResourceRelationTypeEntity; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.exception.ResourceTypeNotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import ch.puzzle.itc.mobiliar.common.util.DefaultResourceTypeDefinition; /** diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/boundary/ResourceRelationLocator.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/boundary/ResourceRelationLocator.java index 77421b7aa..6403a0df2 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/boundary/ResourceRelationLocator.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/boundary/ResourceRelationLocator.java @@ -30,8 +30,8 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.control.ResourceRelationRepository; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.business.utils.ValidationHelper; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; @Stateless public class ResourceRelationLocator { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/control/ResourceRelationConfigurationService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/control/ResourceRelationConfigurationService.java index 0b20da793..4270a5512 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/control/ResourceRelationConfigurationService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/resourcerelation/control/ResourceRelationConfigurationService.java @@ -25,8 +25,6 @@ import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwner; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.AbstractResourceRelationEntity; -import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; -import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ProvidedResourceRelationEntity; public class ResourceRelationConfigurationService { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/shakedown/control/ShakedownStpService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/shakedown/control/ShakedownStpService.java index dae845b4b..c9c42f802 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/shakedown/control/ShakedownStpService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/shakedown/control/ShakedownStpService.java @@ -42,7 +42,6 @@ import ch.puzzle.itc.mobiliar.business.shakedown.entity.ShakedownStpEntity; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.StpNotFoundException; import ch.puzzle.itc.mobiliar.common.exception.TemplateNotDeletableException; @@ -91,7 +90,7 @@ public List getSTPsWithoutSTS() { } @HasPermission(permission = Permission.SHAKEDOWNTEST, action = DELETE) - public void deleteSTPEntity(final Integer stpId) throws GeneralDBException, StpNotFoundException { + public void deleteSTPEntity(final Integer stpId) throws StpNotFoundException, TemplateNotDeletableException { ShakedownStpEntity shakedownStpEntity = getSTPById(stpId); if (shakedownStpEntity == null) { String message = "Die zu löschende STP Entität ist nicht vorhanden "; @@ -101,15 +100,7 @@ public void deleteSTPEntity(final Integer stpId) throws GeneralDBException, StpN // If delete SPT, delete all defined testing-template with // this STP - try { - templatesScreenDomainService.deleteSTPTemplate(shakedownStpEntity.getStpName()); - } - catch (TemplateNotDeletableException e) { - String message = "Bei der Suche einer STP Entität mit der Id : " + stpId - + " ist ein Fehler aufgetreten."; - log.log(Level.SEVERE, message, e); - throw new GeneralDBException(message, e); - } + templatesScreenDomainService.deleteSTPTemplate(shakedownStpEntity.getStpName()); em.remove(shakedownStpEntity); log.info("STP mit der Id: " + stpId + " wurde aus der DB gelöscht"); @@ -175,7 +166,6 @@ public ShakedownStpEntity createNewSTP(final String newSTPName, final String new * @param stpEntity * @param args * @return list with not added args or null if some error occurs - * @throws GeneralDBException */ @HasPermission(permission = Permission.SHAKEDOWNTEST, action = UPDATE) public List editSTPEntity(final ShakedownStpEntity stpEntity, final List args) { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/boundary/SoftlinkRelationBoundary.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/boundary/SoftlinkRelationBoundary.java index 137c30194..f30360fef 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/boundary/SoftlinkRelationBoundary.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/boundary/SoftlinkRelationBoundary.java @@ -57,43 +57,30 @@ public void createSoftlinkRelation(ForeignableOwner creatingOwner, Integer cpiRe ResourceEntity cpiResource = entityManager.find(ResourceEntity.class, cpiResourceId); permissionService.checkPermissionAndFireException(Permission.RESOURCE, null, Action.UPDATE, cpiResource.getResourceGroup(), null, null); - if (cpiResource != null) { - - SoftlinkRelationEntity softlinkRelation = cpiResource.getSoftlinkRelation(); - - if (softlinkRelation == null){ - softlinkRelation = new SoftlinkRelationEntity(); - softlinkRelation.setOwner(creatingOwner); - softlinkRelation.setCpiResource(cpiResource); - softlinkRelation.setSoftlinkRef(softlinkReference); - - } else { - int beforeChangeForeignableFieldHashCode = softlinkRelation.foreignableFieldHashCode(); - softlinkRelation.setSoftlinkRef(softlinkReference); - foreignableService.verifyEditableByOwner(creatingOwner, beforeChangeForeignableFieldHashCode, softlinkRelation); - } - - softlinkRelationService.setSoftlinkRelation(cpiResource, softlinkRelation); - + SoftlinkRelationEntity softlinkRelation = cpiResource.getSoftlinkRelation(); + if (softlinkRelation == null){ + softlinkRelation = new SoftlinkRelationEntity(); + softlinkRelation.setOwner(creatingOwner); + softlinkRelation.setCpiResource(cpiResource); + softlinkRelation.setSoftlinkRef(softlinkReference); } else { - throw new RuntimeException("No resource found for id "+ cpiResourceId); + int beforeChangeForeignableFieldHashCode = softlinkRelation.foreignableFieldHashCode(); + softlinkRelation.setSoftlinkRef(softlinkReference); + foreignableService.verifyEditableByOwner(creatingOwner, beforeChangeForeignableFieldHashCode, softlinkRelation); } + + softlinkRelationService.setSoftlinkRelation(cpiResource, softlinkRelation); } public void removeRelationForResource(ForeignableOwner deletingOwner, Integer resourceId) throws ForeignableOwnerViolationException { ResourceEntity cpiResource = entityManager.find(ResourceEntity.class, resourceId); permissionService.checkPermissionAndFireException(Permission.RESOURCE, null, Action.UPDATE, cpiResource.getResourceGroup(), null, null); - if (cpiResource != null) { - SoftlinkRelationEntity softlinkRelation = cpiResource.getSoftlinkRelation(); - if (softlinkRelation != null){ - foreignableService.verifyDeletableByOwner(deletingOwner, softlinkRelation); - - softlinkRelationService.removeSoftlinkRelation(cpiResource); - } + SoftlinkRelationEntity softlinkRelation = cpiResource.getSoftlinkRelation(); + if (softlinkRelation != null){ + foreignableService.verifyDeletableByOwner(deletingOwner, softlinkRelation); - } else { - throw new RuntimeException("No resource found for id "+ resourceId); + softlinkRelationService.removeSoftlinkRelation(cpiResource); } } @@ -101,14 +88,9 @@ public void editSoftlinkRelation(ForeignableOwner editingUser, SoftlinkRelationE SoftlinkRelationEntity softlinkRelation = entityManager.find(SoftlinkRelationEntity.class, Objects.requireNonNull(editedSoftlinkRelation, "editedSoftlinkRelation must not be null!").getId()); permissionService.checkPermissionAndFireException(Permission.RESOURCE, null, Action.UPDATE, softlinkRelation.getCpiResource().getResourceGroup(), null, null); - if (softlinkRelation != null) { - int beforeChangeForeignableFieldHashCode = softlinkRelation.foreignableFieldHashCode(); - SoftlinkRelationEntity mergedSoftlinkRelation = entityManager.merge(editedSoftlinkRelation); - foreignableService.verifyEditableByOwner(editingUser, beforeChangeForeignableFieldHashCode, mergedSoftlinkRelation); - - } else { - throw new RuntimeException("No softlink relation found for "+ editedSoftlinkRelation); - } + int beforeChangeForeignableFieldHashCode = softlinkRelation.foreignableFieldHashCode(); + SoftlinkRelationEntity mergedSoftlinkRelation = entityManager.merge(editedSoftlinkRelation); + foreignableService.verifyEditableByOwner(editingUser, beforeChangeForeignableFieldHashCode, mergedSoftlinkRelation); } public ResourceEntity getSoftlinkResolvableSlaveResource(SoftlinkRelationEntity softlinkRelation, ReleaseEntity release){ diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/boundary/TemplateEditor.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/boundary/TemplateEditor.java index f2690ad14..641d324cf 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/boundary/TemplateEditor.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/boundary/TemplateEditor.java @@ -27,6 +27,7 @@ import ch.puzzle.itc.mobiliar.business.environment.entity.ContextDependency; import ch.puzzle.itc.mobiliar.business.environment.entity.HasContexts; import ch.puzzle.itc.mobiliar.business.environment.entity.HasTypeContext; +import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceContextEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceTypeContextEntity; @@ -38,12 +39,16 @@ import ch.puzzle.itc.mobiliar.business.security.entity.Permission; import ch.puzzle.itc.mobiliar.business.security.interceptor.HasPermission; import ch.puzzle.itc.mobiliar.business.template.control.FreemarkerSyntaxValidator; +import ch.puzzle.itc.mobiliar.business.template.control.TemplatesScreenDomainService; import ch.puzzle.itc.mobiliar.business.template.entity.RevisionInformation; import ch.puzzle.itc.mobiliar.business.template.entity.TemplateDescriptorEntity; import ch.puzzle.itc.mobiliar.common.exception.AMWException; import ch.puzzle.itc.mobiliar.common.exception.NotAuthorizedException; +import ch.puzzle.itc.mobiliar.common.exception.NotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.exception.ResourceTypeNotFoundException; import ch.puzzle.itc.mobiliar.common.exception.TemplateNotDeletableException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import ch.puzzle.itc.mobiliar.common.util.SystemCallTemplate; import org.apache.commons.lang3.StringUtils; import org.hibernate.envers.AuditReader; @@ -77,8 +82,14 @@ public class TemplateEditor { @Inject FreemarkerSyntaxValidator freemarkerValidator; - @Inject - AuditService auditService; + @Inject + AuditService auditService; + + @Inject + ResourceLocator resourceLocator; + + @Inject + TemplatesScreenDomainService templateService; @Inject private Logger log; @@ -90,9 +101,9 @@ public TemplateDescriptorEntity getTemplateById(Integer templateId) { public TemplateDescriptorEntity getTemplateByIdAndRevision(Integer templateId, Number revisionId) { TemplateDescriptorEntity templateDescriptorEntity = AuditReaderFactory.get(entityManager).find( TemplateDescriptorEntity.class, templateId, revisionId); - //We have to ensure, that the target platforms are loaded. To make sure, that the compiler doesn't optimize the access to the target platforms away, we have to do this ugly hack. - templateDescriptorEntity.getTargetPlatforms().size(); - return templateDescriptorEntity; + //We have to ensure, that the target platforms are loaded. To make sure, that the compiler doesn't optimize the access to the target platforms away, we have to do this ugly hack. + templateDescriptorEntity.getTargetPlatforms().size(); + return templateDescriptorEntity; } public List getTemplateRevisions(Integer templateId) { @@ -108,28 +119,6 @@ public List getTemplateRevisions(Integer templateId) { return result; } - public List loadTemplateDescriptors(HasContexts hasContext) { - hasContext = entityManager.find(hasContext.getClass(), hasContext.getId()); - List> dependencies = hasContext.getContextsByLowestContext(contextService.getGlobalResourceContextEntity()); - List templates = new ArrayList<>(); - for (ContextDependency dep : dependencies) { - templates.addAll(dep.getTemplates()); - } - Collections.sort(templates, new Comparator() { - - @Override - public int compare(TemplateDescriptorEntity t1, TemplateDescriptorEntity t2) { - if (t1 == null || t1.getName() == null) { - return t2 == null || t2.getName() == null ? 0 : -1; - } else { - return t2 == null ? 1 : t1.getName().compareTo(t2.getName()); - } - } - }); - return templates; - } - - @TransactionAttribute(TransactionAttributeType.REQUIRED) boolean hasTemplateWithSameName(TemplateDescriptorEntity template, HasContexts hasContext) { for (ContextDependency c : hasContext.getContextsByLowestContext(contextService.getGlobalResourceContextEntity())) { @@ -167,7 +156,7 @@ public > void saveTemplateForRelation(TemplateDescripto } @HasPermission(permission = Permission.RESOURCE_TEMPLATE, oneOfAction = {Action.UPDATE, Action.CREATE}) - public void saveTemplateForResource(TemplateDescriptorEntity template, Integer resourceId, + public void saveTemplateForResource(TemplateDescriptorEntity template, ResourceEntity resourceEntity, boolean testingMode) throws AMWException { permissionService.assertHasPermissionShakedownTestMode(testingMode); if (!testingMode) { @@ -176,10 +165,24 @@ public void saveTemplateForResource(TemplateDescriptorEntity template, Integer r action, "create/ modify resource templates"); } - ResourceEntity resourceEntity = entityManager.find(ResourceEntity.class, resourceId); saveTemplate(template, resourceEntity); } + public void saveTemplateForResource(TemplateDescriptorEntity template, Integer resourceId, + boolean testingMode) throws AMWException { + ResourceEntity resourceEntity = entityManager.find(ResourceEntity.class, resourceId); + this.saveTemplateForResource(template, resourceEntity, testingMode); + } + + public void saveTemplateForResource(TemplateDescriptorEntity template, String resourceGroupName, String releaseName, + boolean testingMode) throws AMWException { + ResourceEntity resourceEntity = resourceLocator.getResourceByGroupNameAndRelease(resourceGroupName, releaseName); + if (resourceEntity == null) { + throw new ResourceNotFoundException("Resource not found"); + } + this.saveTemplateForResource(template, resourceEntity, testingMode); + } + @HasPermission(permission = Permission.RESOURCETYPE_TEMPLATE, oneOfAction = {Action.UPDATE, Action.CREATE}) public void saveTemplateForResourceType(TemplateDescriptorEntity template, Integer resourceTypeId, boolean testingMode) throws AMWException { @@ -194,33 +197,33 @@ public void saveTemplateForResourceType(TemplateDescriptorEntity template, Integ saveTemplate(template, resourceTypeEntity); } - void validateTemplate(TemplateDescriptorEntity templateDescriptorEntity) throws AMWException { + void validateTemplate(TemplateDescriptorEntity templateDescriptorEntity) throws ValidationException { if (StringUtils.isEmpty(templateDescriptorEntity.getName())) { - throw new AMWException("The template name must not be empty"); + throw new ValidationException("The template name must not be empty"); } if (templateDescriptorEntity.getTargetPath() != null && templateDescriptorEntity.getTargetPath() .startsWith("/")) { - throw new AMWException("Absolute paths are not allowed for file path"); + throw new ValidationException("Absolute paths are not allowed for file path"); } if (templateDescriptorEntity.getTargetPath() != null && templateDescriptorEntity.getTargetPath() .contains("../")) { - throw new AMWException("No path traversals like '../' allowed in file path"); + throw new ValidationException("No path traversals like '../' allowed in file path"); } } - void saveTemplate(TemplateDescriptorEntity template, HasContexts hasContext) throws AMWException { + void saveTemplate(TemplateDescriptorEntity template, HasContexts hasContext) throws ValidationException, AMWException { validateTemplate(template); freemarkerValidator.validateFreemarkerSyntax(template.getFileContent()); hasContext = entityManager.find(hasContext.getClass(), hasContext.getId()); auditService.storeIdInThreadLocalForAuditLog(hasContext); if (hasTemplateWithSameName(template, hasContext)) { - throw new AMWException("The defined template name is already in use"); + throw new ValidationException("The defined template name is already in use"); } if (hasContext instanceof HasTypeContext && hasTemplateWithSameName(template, ((HasTypeContext) hasContext).getTypeContext())) { - throw new AMWException("The defined template name is already in use"); + throw new ValidationException("The defined template name is already in use"); } @@ -242,13 +245,17 @@ && hasTemplateWithSameName(template, ((HasTypeContext) hasContext).getTypeCon */ public void removeTemplate(Integer templateId) throws TemplateNotDeletableException { TemplateDescriptorEntity templateDescriptor = entityManager.find(TemplateDescriptorEntity.class, templateId); + this.removeTemplate(templateDescriptor); + } + + private void removeTemplate(TemplateDescriptorEntity templateDescriptor) throws TemplateNotDeletableException { if (templateDescriptor != null && templateDescriptor.getName() != null && SystemCallTemplate.getName().equals(templateDescriptor.getName())) { String message = SystemCallTemplate.getName() + " Template can't be deleted since it is a system template!"; log.info(message); throw new TemplateNotDeletableException(message); } - AbstractContext owner = getOwnerOfTemplate(templateDescriptor); + AbstractContext owner = templateService.getOwnerOfTemplate(templateDescriptor); if (owner != null) { if (owner instanceof ResourceContextEntity && !permissionService.hasPermission(Permission.RESOURCE_TEMPLATE, null, @@ -279,53 +286,29 @@ public void removeTemplate(Integer templateId) throws TemplateNotDeletableExcept owner.removeTemplate(templateDescriptor); } entityManager.remove(templateDescriptor); - log.info("Template " + templateId + " has been deleted successfully."); + log.info("Template " + templateDescriptor.getId() + " has been deleted successfully."); } - @TransactionAttribute(TransactionAttributeType.REQUIRED) - AbstractContext getOwnerOfTemplate(TemplateDescriptorEntity templateDescriptor) { - // ContextEntity - AbstractContext c; - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery( - "select distinct n from ContextEntity n where :templ member of n.templates") - .setParameter("templ", templateDescriptor)); - if (c != null) { - return c; - } - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery( - "select distinct n from ContextTypeEntity n where :templ member of n.templates") - .setParameter("templ", templateDescriptor)); - if (c != null) { - return c; - } - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery( - "select distinct n from ResourceContextEntity n where :templ member of n.templates") - .setParameter("templ", templateDescriptor)); - if (c != null) { - return c; - } - c = (AbstractContext) getSingleObjectOrNull(entityManager - .createQuery( - "select distinct n from ResourceRelationContextEntity n where :templ member of n.templates") - .setParameter("templ", templateDescriptor)); - if (c != null) { - return c; + public void removeTemplate(String resourceGroupName, String releaseName, String templateName, boolean testingMode) + throws ValidationException, TemplateNotDeletableException, NotFoundException { + ResourceEntity resource = resourceLocator.getResourceByGroupNameAndRelease(resourceGroupName, releaseName); + if (resource == null) { + throw new ResourceNotFoundException("Resource not found"); } - c = (AbstractContext) getSingleObjectOrNull(entityManager - .createQuery( - "select distinct n from ResourceRelationTypeContextEntity n where :templ member of n.templates") - .setParameter("templ", templateDescriptor)); - if (c != null) { - return c; - } - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery( - "select distinct n from ResourceTypeContextEntity n where :templ member of n.templates") - .setParameter("templ", templateDescriptor)); - if (c != null) { - return c; + List templates = templateService.getGlobalTemplateDescriptorsForResource(resource, testingMode); + + TemplateDescriptorEntity temp = null; + for (TemplateDescriptorEntity template : templates) { + if (templateName.equals(template.getName())) { + temp = template; + break; + } } - return null; + if (temp == null) { + throw new NotFoundException("Template not found"); + } + this.removeTemplate(temp); } @TransactionAttribute(TransactionAttributeType.REQUIRED) diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/control/FreemarkerSyntaxValidator.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/control/FreemarkerSyntaxValidator.java index 6608f1ff1..9791fc37e 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/control/FreemarkerSyntaxValidator.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/control/FreemarkerSyntaxValidator.java @@ -26,6 +26,7 @@ import javax.ejb.Stateless; import ch.puzzle.itc.mobiliar.common.exception.AMWException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import freemarker.cache.StringTemplateLoader; import freemarker.core.ParseException; import freemarker.template.Configuration; @@ -38,10 +39,11 @@ public class FreemarkerSyntaxValidator { * * @param freemarkerContent * @throws AMWException - * if the template can not be successfully validate. The error message distincts between + * The error message distincts between * parsing exceptions and other (unexpected) potential issues. + * @throws ValidationException if the template can not be successfully validate. */ - public void validateFreemarkerSyntax(String freemarkerContent) throws AMWException { + public void validateFreemarkerSyntax(String freemarkerContent) throws ValidationException, AMWException { Objects.requireNonNull(freemarkerContent, "freemarker content must not be null"); Configuration c = new Configuration(); c.setStrictSyntaxMode(true); @@ -56,7 +58,7 @@ public void validateFreemarkerSyntax(String freemarkerContent) throws AMWExcepti } catch (ParseException e) { // Validation failed! - was not able to parse the template! - throw new AMWException("The template is syntactically incorrect: " + e.getMessage(), e); + throw new ValidationException("The template is syntactically incorrect: " + e.getMessage(), e); } catch (IOException e) { // Something else went wrong diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/control/TemplatesScreenDomainService.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/control/TemplatesScreenDomainService.java index 7fe166b19..bcb136bc1 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/control/TemplatesScreenDomainService.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/control/TemplatesScreenDomainService.java @@ -23,6 +23,7 @@ import ch.puzzle.itc.mobiliar.business.environment.control.ContextDomainService; import ch.puzzle.itc.mobiliar.business.environment.entity.AbstractContext; import ch.puzzle.itc.mobiliar.business.property.entity.*; +import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.*; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.*; import ch.puzzle.itc.mobiliar.business.security.entity.Action; @@ -59,6 +60,9 @@ public class TemplatesScreenDomainService { @Inject private ContextDomainService contextService; + @Inject + ResourceLocator resourceLocator; + @Inject ResourceRelationService resourceRelationService; @@ -67,12 +71,16 @@ public List getGlobalTemplateDescriptorsForResourceTyp return getTemplateDescriptorsForResourceTypeContext(contextService.getGlobalResourceContextEntity(), resourceType, new ArrayList(), testing); } - public List getGlobalTemplateDescriptorsForResource(ResourceEntity resource, boolean testing) { resource = entityManager.find(ResourceEntity.class, resource.getId()); return getTemplateDescriptorsForResourceContext(contextService.getGlobalResourceContextEntity(), resource, new ArrayList(), testing); } + public List getGlobalTemplateDescriptorsForResource(String resourceGroupName, String releaseName, boolean testing) throws ValidationException { + ResourceEntity resource = resourceLocator.getResourceByGroupNameAndRelease(resourceGroupName, releaseName); + return getTemplateDescriptorsForResourceContext(contextService.getGlobalResourceContextEntity(), resource, new ArrayList(), testing); + } + public List getGlobalTemplatesForResourceRelation(ResourceEditRelation relation, boolean testing) { return getTemplateDescriptorsForResourceRelationContext(contextService.getGlobalResourceContextEntity(), resourceRelationService.getResourceRelation(relation.getResRelId()), new ArrayList(), testing); } @@ -83,7 +91,7 @@ public List getGlobalTemplatesForResourceRelationType( return getTemplateDescriptorsForResourceRelationTypeContext(contextService.getGlobalResourceContextEntity(), resRelType, new ArrayList(), testing); } - public List getTemplatesForResourceRelation(AbstractResourceRelationEntity relation, boolean testing) throws ResourceNotFoundException, GeneralDBException { + public List getTemplatesForResourceRelation(AbstractResourceRelationEntity relation, boolean testing) throws ResourceNotFoundException { return getTemplateDescriptorsForResourceRelationContext(contextService.getGlobalResourceContextEntity(), resourceRelationService.getResourceRelation(relation.getId()), new ArrayList(), testing); } @@ -225,7 +233,6 @@ private List getTemplateListByName(String templateName * @param templateName * @throws ResourceTypeNotFoundException * @throws TemplateNotDeletableException - * @throws GeneralDBException */ public void deleteSTPTemplate(String templateName) throws TemplateNotDeletableException { for(TemplateDescriptorEntity template : getTemplateListByName(templateName)){ @@ -239,7 +246,6 @@ public void deleteSTPTemplate(String templateName) throws TemplateNotDeletableEx * Löscht die Template von eine ResourceType. * * @param selectedTemplateId - * @throws GeneralDBException * @throws ResourceTypeNotFoundException * @throws TemplateNotDeletableException */ @@ -258,35 +264,44 @@ private void doRemoveTemplate(Integer selectedTemplateId) throws TemplateNotDele log.info("Template Id: " + selectedTemplateId + " was deleted successfully."); } - private AbstractContext getOwnerOfTemplate(TemplateDescriptorEntity templateDescriptor) { + public AbstractContext getOwnerOfTemplate(TemplateDescriptorEntity templateDescriptor) { // ContextEntity AbstractContext c; - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery("select distinct n from ContextEntity n where :templ member of n.templates").setParameter("templ", templateDescriptor)); + c = (AbstractContext) getSingleObjectOrNull( + entityManager.createQuery("select distinct n from ContextEntity n where :templ member of n.templates") + .setParameter("templ", templateDescriptor)); if (c != null) { return c; } - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery("select distinct n from ContextTypeEntity n where :templ member of n.templates") + c = (AbstractContext) getSingleObjectOrNull(entityManager + .createQuery("select distinct n from ContextTypeEntity n where :templ member of n.templates") .setParameter("templ", templateDescriptor)); if (c != null) { return c; } - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery("select distinct n from ResourceContextEntity n where :templ member of n.templates").setParameter("templ", - templateDescriptor)); + c = (AbstractContext) getSingleObjectOrNull(entityManager + .createQuery("select distinct n from ResourceContextEntity n where :templ member of n.templates") + .setParameter("templ", templateDescriptor)); if (c != null) { return c; } - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery("select distinct n from ResourceRelationContextEntity n where :templ member of n.templates").setParameter("templ", - templateDescriptor)); + c = (AbstractContext) getSingleObjectOrNull(entityManager + .createQuery( + "select distinct n from ResourceRelationContextEntity n where :templ member of n.templates") + .setParameter("templ", templateDescriptor)); if (c != null) { return c; } - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery("select distinct n from ResourceRelationTypeContextEntity n where :templ member of n.templates").setParameter("templ", - templateDescriptor)); + c = (AbstractContext) getSingleObjectOrNull(entityManager + .createQuery( + "select distinct n from ResourceRelationTypeContextEntity n where :templ member of n.templates") + .setParameter("templ", templateDescriptor)); if (c != null) { return c; } - c = (AbstractContext) getSingleObjectOrNull(entityManager.createQuery("select distinct n from ResourceTypeContextEntity n where :templ member of n.templates").setParameter("templ", - templateDescriptor)); + c = (AbstractContext) getSingleObjectOrNull(entityManager + .createQuery("select distinct n from ResourceTypeContextEntity n where :templ member of n.templates") + .setParameter("templ", templateDescriptor)); return c; } diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/entity/TemplateDescriptorEntity.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/entity/TemplateDescriptorEntity.java index f1bfa7b9a..70d3e0f2a 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/entity/TemplateDescriptorEntity.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/template/entity/TemplateDescriptorEntity.java @@ -177,6 +177,7 @@ public String getRelatedResourceIdentifier() { return relatedResourceIdentifier; } + //TODO: unused? public void setRelatedResourceIdentifier(String relatedResourceIdentifier) { this.relatedResourceIdentifier = relatedResourceIdentifier; } diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/ValidationHelper.java b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/ValidationHelper.java index cfe537480..05a257de5 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/ValidationHelper.java +++ b/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/ValidationHelper.java @@ -20,6 +20,8 @@ package ch.puzzle.itc.mobiliar.business.utils; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; + public class ValidationHelper { /** diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/ResourceEditPropertyBuilder.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/ResourceEditPropertyBuilder.java index 14fa8f011..3a4fc59c0 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/ResourceEditPropertyBuilder.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/ResourceEditPropertyBuilder.java @@ -20,13 +20,6 @@ package ch.puzzle.itc.mobiliar.builders; -import java.io.Reader; -import java.io.StringReader; -import java.sql.Clob; -import java.sql.SQLException; - -import org.mockito.Mockito; - import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwner; import ch.puzzle.itc.mobiliar.business.property.entity.PropertyDescriptorEntity; import ch.puzzle.itc.mobiliar.business.property.entity.ResourceEditProperty; @@ -325,16 +318,4 @@ public ResourceEditProperty build() { typeContextId, descriptorId, propContName, typeContName, typeId, propertyValueTypeId, masterTypeId, typeName, validationRegex, propertyId, origin, loadedFor, resourceName, descriptorOrigin, fcOwner, fcExternalKey, fcExternalLink); } - - private Clob convert(String value) { - Clob clob = Mockito.mock(Clob.class); - Reader reader = new StringReader(value); - try { - Mockito.when(clob.getCharacterStream()).thenReturn(reader); - } - catch (SQLException e) { - // should not happen in mocking mode - } - return clob; - } } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/ResourceTypeEntityBuilder.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/ResourceTypeEntityBuilder.java index 82b8bba19..2184ec710 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/ResourceTypeEntityBuilder.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/ResourceTypeEntityBuilder.java @@ -24,7 +24,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.util.Collection; import java.util.HashSet; import java.util.Set; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/SoftlinkRelationEntityBuilder.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/SoftlinkRelationEntityBuilder.java index de1c647b4..f2610b902 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/SoftlinkRelationEntityBuilder.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/builders/SoftlinkRelationEntityBuilder.java @@ -25,9 +25,6 @@ import ch.puzzle.itc.mobiliar.business.softlinkRelation.entity.SoftlinkRelationEntity; import org.mockito.Mockito; -import java.util.HashSet; -import java.util.Set; - import static org.mockito.Mockito.when; /** diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/applicationinfo/boundary/ApplicationVersionServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/applicationinfo/boundary/ApplicationVersionServiceTest.java index dcef6a263..e27805708 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/applicationinfo/boundary/ApplicationVersionServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/applicationinfo/boundary/ApplicationVersionServiceTest.java @@ -33,11 +33,11 @@ public void getObfuscatedApplicationConfigurationKeyValuePairsShouldObfuscateVal // then for (ConfigurationKeyValuePair keyValuePair : obfuscatedKeyValuePairs) { if (keyValuePair.getKey().isSecretValue()) { - assertThat(keyValuePair.getValue(), is(applicationVersionService.OBFUSCATED)); - assertThat(keyValuePair.getDefaultValue(), is(applicationVersionService.OBFUSCATED)); + assertThat(keyValuePair.getValue(), is(ApplicationVersionService.OBFUSCATED)); + assertThat(keyValuePair.getDefaultValue(), is(ApplicationVersionService.OBFUSCATED)); } else { - assertThat(keyValuePair.getValue(), not(applicationVersionService.OBFUSCATED)); - assertThat(keyValuePair.getDefaultValue(), not(applicationVersionService.OBFUSCATED)); + assertThat(keyValuePair.getValue(), not(ApplicationVersionService.OBFUSCATED)); + assertThat(keyValuePair.getDefaultValue(), not(ApplicationVersionService.OBFUSCATED)); } } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/configurationtag/control/TagConfigurationServicePersistenceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/configurationtag/control/TagConfigurationServicePersistenceTest.java index e9e6170a6..a0c9e2b41 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/configurationtag/control/TagConfigurationServicePersistenceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/configurationtag/control/TagConfigurationServicePersistenceTest.java @@ -25,7 +25,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceFactory; import ch.puzzle.itc.mobiliar.business.security.control.PermissionService; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.test.testrunner.PersistenceTestRunner; import org.junit.Assert; @@ -69,7 +68,7 @@ public void before() { } @Test - public void test_tagConfiguration() throws ResourceNotFoundException, ElementAlreadyExistsException, GeneralDBException { + public void test_tagConfiguration() throws ResourceNotFoundException, ElementAlreadyExistsException { // given ResourceEntity as1 = ResourceFactory.createNewResource("appServer1"); entityManager.persist(as1); diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/domain/TestUtils.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/domain/TestUtils.java index 4bfa6f557..76de0e3d6 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/domain/TestUtils.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/domain/TestUtils.java @@ -21,13 +21,12 @@ package ch.puzzle.itc.mobiliar.business.domain; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import org.apache.commons.io.Charsets; - import ch.puzzle.itc.mobiliar.business.generator.control.extracted.properties.AppServerRelationProperties; import ch.puzzle.itc.mobiliar.business.generator.control.extracted.templates.GenerationUnit; import ch.puzzle.itc.mobiliar.business.property.entity.AmwResourceTemplateModel; @@ -43,7 +42,7 @@ public class TestUtils { public static String readRecursionTemplate() { try { - return Resources.toString(Resources.getResource("rekursiv_macro_4.txt"), Charsets.UTF_8); + return Resources.toString(Resources.getResource("rekursiv_macro_4.txt"), StandardCharsets.UTF_8); } catch (IOException e) { e.printStackTrace(); diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/boundary/FunctionsBoundaryTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/boundary/FunctionsBoundaryTest.java index 7886707c1..4fb39855f 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/boundary/FunctionsBoundaryTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/boundary/FunctionsBoundaryTest.java @@ -27,6 +27,8 @@ import ch.puzzle.itc.mobiliar.business.security.boundary.PermissionBoundary; import ch.puzzle.itc.mobiliar.common.exception.NotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,7 +47,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceTypeEntity; import ch.puzzle.itc.mobiliar.business.template.control.FreemarkerSyntaxValidator; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/control/FunctionServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/control/FunctionServiceTest.java index 584749070..42fc82439 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/control/FunctionServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/control/FunctionServiceTest.java @@ -64,17 +64,15 @@ public class FunctionServiceTest { private static final Integer FUNCTION_ID_9 = 9; private static final Integer FUNCTION_ID_10 = 10; private static final Integer FUNCTION_ID_11 = 11; - private static final Integer FUNCTION_ID_12 = 12; private final AmwFunctionEntity FUNCTION_A = createFunction(FUNCTION_NAME_A, FUNCTION_ID_1); private final AmwFunctionEntity FUNCTION_A_OVERWRITE = createOverwritingFunction(FUNCTION_A, FUNCTION_ID_2); private final AmwFunctionEntity FUNCTION_A_OVERWRITE_2 = createOverwritingFunction(FUNCTION_A_OVERWRITE, FUNCTION_ID_6); - private final AmwFunctionEntity OTHER_FUNCTION_A = createFunction(FUNCTION_NAME_A, FUNCTION_ID_12); + private final AmwFunctionEntity OTHER_FUNCTION_A = createFunction(FUNCTION_NAME_A, FUNCTION_ID_11); private final AmwFunctionEntity FUNCTION_B = createFunction(FUNCTION_NAME_B, FUNCTION_ID_3); private final AmwFunctionEntity FUNCTION_B_OVERWRITE = createOverwritingFunction(FUNCTION_B, FUNCTION_ID_4); - private final AmwFunctionEntity FUNCTION_B_OVERWRITE_2 = createOverwritingFunction(FUNCTION_B, FUNCTION_ID_11); private final AmwFunctionEntity FUNCTION_C = createFunction(FUNCTION_NAME_C, FUNCTION_ID_5); private final AmwFunctionEntity FUNCTION_C_OVERWRITE = createOverwritingFunction(FUNCTION_C, FUNCTION_ID_7); diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/entity/AmwFunctionEntityBuilder.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/entity/AmwFunctionEntityBuilder.java index d080cb84a..544ec7702 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/entity/AmwFunctionEntityBuilder.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/function/entity/AmwFunctionEntityBuilder.java @@ -22,13 +22,9 @@ import ch.puzzle.itc.mobiliar.business.property.entity.MikEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; -import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceType; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceTypeEntity; import org.mockito.Mockito; -import javax.persistence.CascadeType; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; import java.util.Arrays; import java.util.HashSet; import java.util.Set; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/GeneratedTemplateTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/GeneratedTemplateTest.java index 6c4c7dc12..6b5d49c2f 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/GeneratedTemplateTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/GeneratedTemplateTest.java @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import static org.junit.Assert.*; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/GenerationUnitGenerationResultTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/GenerationUnitGenerationResultTest.java index 8a4092050..b8ed3639e 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/GenerationUnitGenerationResultTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/GenerationUnitGenerationResultTest.java @@ -27,8 +27,6 @@ import java.util.ArrayList; import java.util.List; -import ch.puzzle.itc.mobiliar.business.generator.control.GeneratedTemplate; -import ch.puzzle.itc.mobiliar.business.generator.control.GenerationUnitGenerationResult; import org.junit.Test; import org.mockito.Mockito; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/PropertiesValueResolverTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/PropertiesValueResolverTest.java index 8345f7503..227de8375 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/PropertiesValueResolverTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/PropertiesValueResolverTest.java @@ -68,21 +68,4 @@ public void testValueRegex() { assertTrue(m.matches()); assertEquals("name", m.group(1)); } - - @SuppressWarnings("unchecked") - private Object get(Map map, String... keys) { - Object result = null; - - for (String key : keys) { - Object nested = map.get(key); - if (nested instanceof Map) { - map = (Map) nested; - } - else { - result = nested; - } - } - return result; - - } } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/properties/SimpleAppServerRelationPropertiesTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/properties/SimpleAppServerRelationPropertiesTest.java index 3eafd9295..2b94f5ef1 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/properties/SimpleAppServerRelationPropertiesTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/properties/SimpleAppServerRelationPropertiesTest.java @@ -22,7 +22,7 @@ import static ch.puzzle.itc.mobiliar.test.EntityBuilderType.APP; import static ch.puzzle.itc.mobiliar.test.EntityBuilderType.WS; -import static junit.framework.Assert.assertNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/AppServerRelationsTemplateProcessorTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/AppServerRelationsTemplateProcessorTest.java index 49ce8967a..3f8293a8c 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/AppServerRelationsTemplateProcessorTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/AppServerRelationsTemplateProcessorTest.java @@ -33,6 +33,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -115,7 +116,7 @@ public void testWritingFiles() throws IOException { File generatedFile = files.get(0); assertEquals("aPath", generatedFile.getName()); - assertEquals("content", FileUtils.readFileToString(generatedFile)); + assertEquals("content", FileUtils.readFileToString(generatedFile, StandardCharsets.UTF_8)); assertTrue(templateExceptionHandler.isSuccess()); } @@ -134,7 +135,7 @@ public void testNestedResources() throws IOException { generate(templateExceptionHandler); assertEquals(1, files.size()); - assertEquals(lb.getName(), FileUtils.readFileToString(files.get(0))); + assertEquals(lb.getName(), FileUtils.readFileToString(files.get(0), StandardCharsets.UTF_8)); assertTrue(templateExceptionHandler.isSuccess()); } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/GenerationOptionsTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/GenerationOptionsTest.java index be735bae7..d5390380b 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/GenerationOptionsTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/GenerationOptionsTest.java @@ -20,9 +20,7 @@ package ch.puzzle.itc.mobiliar.business.generator.control.extracted.templates; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import org.junit.Test; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/TemplateProcessorBaseTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/TemplateProcessorBaseTest.java index 3bddfa115..f471a9c76 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/TemplateProcessorBaseTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/generator/control/extracted/templates/TemplateProcessorBaseTest.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; @@ -158,7 +159,7 @@ protected void writeFiles() throws FileExistsException, IOException { protected String readFile(String name) throws IOException { for (File file : files) { if (file.getName().equals(name)) { - return FileUtils.readFileToString(file); + return FileUtils.readFileToString(file, StandardCharsets.UTF_8); } } throw new RuntimeException("file not found: " + name); @@ -175,8 +176,7 @@ public static List generateTemplates(GenerationO templates.addAll(results); } - GenerationUnit generationUnit = GenerationUnit.forResource(work.getNodeGenerationUnits(), options.getContext().getNode()); - + GenerationUnit.forResource(work.getNodeGenerationUnits(), options.getContext().getNode()); for (GenerationUnit unit : work.getNodeGenerationUnits()) { if(!unit.isTemplateGenerationDisabled()) { diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/globalfunction/entity/GlobalFunctionEntityTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/globalfunction/entity/GlobalFunctionEntityTest.java index 2cb971435..d0f01c838 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/globalfunction/entity/GlobalFunctionEntityTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/globalfunction/entity/GlobalFunctionEntityTest.java @@ -20,7 +20,6 @@ package ch.puzzle.itc.mobiliar.business.globalfunction.entity; -import ch.puzzle.itc.mobiliar.business.globalfunction.entity.GlobalFunctionEntity; import org.junit.Test; import static org.junit.Assert.*; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/issues/Issue6111RelationIdentifierTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/issues/Issue6111RelationIdentifierTest.java index ad36d6d0d..a9fa4cb9c 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/issues/Issue6111RelationIdentifierTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/issues/Issue6111RelationIdentifierTest.java @@ -52,7 +52,6 @@ public class Issue6111RelationIdentifierTest extends TemplateProcessorBaseTest

result = service.getAppServersWithApplications("app", null, release1); - + service.getAppServersWithApplications("app", null, release1); } } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/CopyResourceDomainServicePersistenceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/CopyResourceDomainServicePersistenceTest.java index 84c272dea..b44aefdaa 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/CopyResourceDomainServicePersistenceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/CopyResourceDomainServicePersistenceTest.java @@ -51,7 +51,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceFactory; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceTypeEntity; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.util.DefaultResourceTypeDefinition; import ch.puzzle.itc.mobiliar.test.testrunner.PersistenceTestRunner; @@ -95,7 +94,6 @@ public void before() { * The propertyDescriptor for 'port' for resource Copy should not be the same as for Origin! * * @throws ResourceNotFoundException - * @throws GeneralDBException */ @Test public void test_propertyOverwrittenInContext() throws ForeignableOwnerViolationException, AMWException { diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/CopyResourceDomainServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/CopyResourceDomainServiceTest.java index d8092b2ca..4ec0c5131 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/CopyResourceDomainServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/CopyResourceDomainServiceTest.java @@ -34,7 +34,7 @@ import org.junit.Before; import org.junit.Test; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; /** diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupRepositoryTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupRepositoryTest.java index 9f056d340..4cf11ec32 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupRepositoryTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceGroupRepositoryTest.java @@ -27,7 +27,6 @@ import ch.puzzle.itc.mobiliar.business.usersettings.entity.FavoriteResourceEntity; import ch.puzzle.itc.mobiliar.business.usersettings.entity.UserSettingsEntity; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.exception.ResourceTypeNotFoundException; import ch.puzzle.itc.mobiliar.common.util.ApplicationServerContainer; @@ -114,7 +113,7 @@ private void init() { } @Test - public void test_loadGroupsForType() throws GeneralDBException, ElementAlreadyExistsException, + public void test_loadGroupsForType() throws ElementAlreadyExistsException, ResourceNotFoundException, ResourceTypeNotFoundException { // given init(); @@ -146,7 +145,7 @@ public void test_loadGroupsForType() throws GeneralDBException, ElementAlreadyEx } @Test - public void test_loadGroupsForType_myAmw() throws GeneralDBException, ElementAlreadyExistsException, ResourceNotFoundException, + public void test_loadGroupsForType_myAmw() throws ElementAlreadyExistsException, ResourceNotFoundException, ResourceTypeNotFoundException { // given init(); diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceImportServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceImportServiceTest.java index eae8a43cf..fa072ce84 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceImportServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/control/ResourceImportServiceTest.java @@ -26,7 +26,6 @@ import ch.puzzle.itc.mobiliar.builders.ReleaseEntityBuilder; import ch.puzzle.itc.mobiliar.common.util.ConfigKey; -import ch.puzzle.itc.mobiliar.common.util.ConfigurationService; import org.junit.Before; import org.junit.Test; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceEntityTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceEntityTest.java index ba4cc0d18..6f220d8cb 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceEntityTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcegroup/entity/ResourceEntityTest.java @@ -34,7 +34,7 @@ import ch.puzzle.itc.mobiliar.common.util.ApplicationServerContainer; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -74,7 +74,7 @@ public void testAddProvidedResourceRelation() { @Test public void testGetRelationById() { // given - Mockito.when(resourceEntity.getRelationById(Matchers.anyInt(), Matchers.anySet())).thenCallRealMethod(); + Mockito.when(resourceEntity.getRelationById(ArgumentMatchers.anyInt(), ArgumentMatchers.anySet())).thenCallRealMethod(); final int slaveResourceId = 21; @@ -96,7 +96,7 @@ public void testGetRelationById() { @Test public void testGetMasterRelation() { // given - Mockito.when(resourceEntity.getMasterRelation(Matchers.any(ResourceEntity.class), Matchers.anySet())).thenCallRealMethod(); + Mockito.when(resourceEntity.getMasterRelation(ArgumentMatchers.any(ResourceEntity.class), ArgumentMatchers.anySet())).thenCallRealMethod(); final int slaveResourceId = 21; final Set relations = new HashSet(); @@ -131,7 +131,7 @@ private ConsumedResourceRelationEntity createConsumedResourceRelation(final int } private ConsumedResourceRelationEntity prepareConsumedSlaveRelationTest() { - Mockito.when(resourceEntity.getConsumedSlaveRelation(Matchers.any(ResourceEntity.class))).thenCallRealMethod(); + Mockito.when(resourceEntity.getConsumedSlaveRelation(ArgumentMatchers.any(ResourceEntity.class))).thenCallRealMethod(); final ConsumedResourceRelationEntity consumedResourceRelationEntity = createConsumedResourceRelation(11, 12); diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcerelation/control/ResourceRelationServicePersistenceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcerelation/control/ResourceRelationServicePersistenceTest.java index 49c744568..e30c4eb9b 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcerelation/control/ResourceRelationServicePersistenceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcerelation/control/ResourceRelationServicePersistenceTest.java @@ -31,7 +31,6 @@ import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ProvidedResourceRelationEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ResourceRelationTypeEntity; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.test.testrunner.PersistenceTestRunner; import org.junit.Before; @@ -190,7 +189,7 @@ public void test_getProvidedRelationsByMasterAndSlave() { } @Test - public void test_doAddResourceRelationForAllReleases() throws GeneralDBException, ResourceNotFoundException, ElementAlreadyExistsException { + public void test_doAddResourceRelationForAllReleases() throws ResourceNotFoundException, ElementAlreadyExistsException { // given ResourceEntityBuilder resourceEntityBuilder = new ResourceEntityBuilder(); ResourceEntity master = resourceEntityBuilder.buildApplicationEntity("master", null, null, false); diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcerelation/entity/ConsumedResourceRelationEntityTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcerelation/entity/ConsumedResourceRelationEntityTest.java index 013ebb211..da219432a 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcerelation/entity/ConsumedResourceRelationEntityTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/resourcerelation/entity/ConsumedResourceRelationEntityTest.java @@ -22,7 +22,6 @@ import ch.puzzle.itc.mobiliar.builders.ResourceEntityBuilder; import ch.puzzle.itc.mobiliar.builders.ResourceRelationEntityBuilder; -import ch.puzzle.itc.mobiliar.builders.TargetPlatformEntityBuilder; import ch.puzzle.itc.mobiliar.business.resourcegroup.control.CopyResourceDomainService; import ch.puzzle.itc.mobiliar.business.resourcegroup.control.CopyResourceDomainServiceTestHelper; import ch.puzzle.itc.mobiliar.business.resourcegroup.control.CopyUnit; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/security/boundary/PermissionBoundaryTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/security/boundary/PermissionBoundaryTest.java index 9ca053ca9..04892f93a 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/security/boundary/PermissionBoundaryTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/security/boundary/PermissionBoundaryTest.java @@ -465,7 +465,7 @@ public void shouldDelegatePermissionAndActionCheckToPermissionService() { @Test(expected=IllegalArgumentException.class) public void shouldThrowAnExceptionIfRequestedPermissionDoesNotExist() { // given // when // then - boolean result = permissionBoundary.hasPermissionForResourceType("NotAPermission", "CREATE", "APP"); + permissionBoundary.hasPermissionForResourceType("NotAPermission", "CREATE", "APP"); } @Test(expected=IllegalArgumentException.class) diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/shakedown/control/ShakedownTestExecutionResultHandlerServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/shakedown/control/ShakedownTestExecutionResultHandlerServiceTest.java index 36583baf4..232dce0af 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/shakedown/control/ShakedownTestExecutionResultHandlerServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/shakedown/control/ShakedownTestExecutionResultHandlerServiceTest.java @@ -31,8 +31,6 @@ import java.util.logging.Level; import java.util.logging.Logger; -import ch.puzzle.itc.mobiliar.business.shakedown.control.ShakedownTestExecutionResultHandlerService; -import ch.puzzle.itc.mobiliar.business.shakedown.control.ShakedownTestService; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/shakedown/xmlmodel/STSTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/shakedown/xmlmodel/STSTest.java index 2c9445641..2ec9f1693 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/shakedown/xmlmodel/STSTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/shakedown/xmlmodel/STSTest.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.List; -import ch.puzzle.itc.mobiliar.business.shakedown.xmlmodel.STS; import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/control/SoftLinkRelationServiceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/control/SoftLinkRelationServiceTest.java index c26d70032..9865258fb 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/control/SoftLinkRelationServiceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/control/SoftLinkRelationServiceTest.java @@ -46,9 +46,9 @@ public void init() { public void shouldSetResourceIdInThreadLocal() { // given ResourceEntity resourceEntity = ResourceEntityBuilder.createResourceEntity("MyResource", 500); - TypedQuery query = mock(TypedQuery.class); + TypedQuery query = mock(TypedQuery.class); when(query.getResultList()).thenReturn(Collections.emptyList()); - when(query.setParameter(anyString(), anyObject())).thenReturn(query); + when(query.setParameter(anyString(), any())).thenReturn(query); when(entityManager.createQuery(any(String.class), eq(SoftlinkRelationEntity.class))).thenReturn(query); // when diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/control/SoftlinkRelationServicePersistenceTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/control/SoftlinkRelationServicePersistenceTest.java index 8a1c704ee..8b76314c1 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/control/SoftlinkRelationServicePersistenceTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/softlinkRelation/control/SoftlinkRelationServicePersistenceTest.java @@ -47,9 +47,9 @@ import java.util.Date; import java.util.logging.Logger; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNull; -import static junit.framework.TestCase.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.verify; /** diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/BaseRepositoryTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/BaseRepositoryTest.java index be9803bc9..08db7e062 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/BaseRepositoryTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/BaseRepositoryTest.java @@ -31,7 +31,7 @@ import java.util.List; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import static org.hamcrest.Matchers.*; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/SessionContextIntegrationTestProducer.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/SessionContextIntegrationTestProducer.java index 4d1c0cfca..86850f7bd 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/SessionContextIntegrationTestProducer.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/SessionContextIntegrationTestProducer.java @@ -20,10 +20,9 @@ package ch.puzzle.itc.mobiliar.business.utils; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; -import javax.annotation.Resource; import javax.ejb.SessionContext; import javax.enterprise.inject.Produces; import javax.enterprise.inject.Specializes; @@ -41,7 +40,7 @@ public class SessionContextIntegrationTestProducer extends SessionContextProduce public SessionContext createSessionContext(){ sessionContext = Mockito.mock(SessionContext.class); - Mockito.when(sessionContext.isCallerInRole(Matchers.anyString())).thenReturn(true); + Mockito.when(sessionContext.isCallerInRole(ArgumentMatchers.anyString())).thenReturn(true); return sessionContext; } } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/ValidationHelperTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/ValidationHelperTest.java index b9a9a1892..d42d292d5 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/ValidationHelperTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/ValidationHelperTest.java @@ -22,6 +22,8 @@ import org.junit.Test; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; + import static org.junit.Assert.*; public class ValidationHelperTest { diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/database/LiquibaseChangeSetTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/database/LiquibaseChangeSetTest.java index ed1002bd5..1867a657d 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/database/LiquibaseChangeSetTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/business/utils/database/LiquibaseChangeSetTest.java @@ -13,10 +13,7 @@ import org.junit.Test; import java.io.File; -import java.io.IOException; -import java.net.URL; import java.sql.DriverManager; -import java.sql.SQLException; import java.util.List; import static junit.framework.TestCase.fail; @@ -30,7 +27,7 @@ public class LiquibaseChangeSetTest { @Test - public void shouldLoadInitialDataSetInEmptyDatabase() throws LiquibaseException, SQLException, ClassNotFoundException { + public void shouldLoadInitialDataSetInEmptyDatabase() throws Exception { // given Class.forName("org.h2.Driver"); conn = DriverManager.getConnection("jdbc:h2:mem:testdata", "sa", ""); @@ -41,6 +38,7 @@ public void shouldLoadInitialDataSetInEmptyDatabase() throws LiquibaseException, //when liquibase.update(new Contexts(), new LabelExpression()); + liquibase.close(); // then must not fail if(conn !=null) { conn.close(); @@ -48,7 +46,7 @@ public void shouldLoadInitialDataSetInEmptyDatabase() throws LiquibaseException, } @Test - public void shouldNotHaveAnyOpenChangeSets() throws LiquibaseException, SQLException, ClassNotFoundException, IOException { + public void shouldNotHaveAnyOpenChangeSets() throws Exception { // given File testDB = EntityManagerProducerIntegrationTestImpl.copyIntegrationTestDB("amwFileDbIntegrationOpenChangeSets.mv.db"); conn = DriverManager.getConnection("jdbc:h2:file:" + testDB.getParent().toString() + "/amwFileDbIntegrationOpenChangeSets", "sa", ""); @@ -72,7 +70,8 @@ public void shouldNotHaveAnyOpenChangeSets() throws LiquibaseException, SQLExcep fail("There are open Database Changesets on the local H2 Database, that can be applied without error, run AMW_db_scripts/update_h2_test_db.sh to apply them directly"); } - if(conn !=null) { + liquibase.close(); + if(conn != null) { conn.close(); } } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/release/ReleaseTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/release/ReleaseTest.java index 612f8a808..7b81dd940 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/release/ReleaseTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/release/ReleaseTest.java @@ -30,7 +30,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.security.control.PermissionService; import ch.puzzle.itc.mobiliar.business.utils.Identifiable; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.exception.TemplatePropertyException; import ch.puzzle.itc.mobiliar.test.PersistingEntityBuilder; @@ -92,7 +91,7 @@ public void before() { } @Test - public void testPropertiesAndRevisions() throws TemplatePropertyException, ResourceNotFoundException, GeneralDBException { + public void testPropertiesAndRevisions() throws TemplatePropertyException, ResourceNotFoundException { AMWTemplateExceptionHandler templateExceptionHandler = new AMWTemplateExceptionHandler(); List list = readProperties(templateExceptionHandler); PropertyEntity property = list.get(0); diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/Entity/Color.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/Entity/Color.java index b6d74859e..0f870b62d 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/Entity/Color.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/Entity/Color.java @@ -20,8 +20,6 @@ package ch.puzzle.itc.mobiliar.test.Entity; -import lombok.Getter; - import javax.persistence.*; @Entity @@ -37,6 +35,7 @@ public class Color { @Version private long v; + @SuppressWarnings("unused") private Color() { // used by JPA } diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/EntityBuilder.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/EntityBuilder.java index ca7a459ef..d8df6cafa 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/EntityBuilder.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/EntityBuilder.java @@ -21,7 +21,6 @@ package ch.puzzle.itc.mobiliar.test; import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwner; -import ch.puzzle.itc.mobiliar.business.generator.control.GeneratorUtils; import ch.puzzle.itc.mobiliar.business.environment.entity.ContextEntity; import ch.puzzle.itc.mobiliar.business.environment.entity.ContextTypeEntity; import ch.puzzle.itc.mobiliar.business.property.entity.PropertyDescriptorEntity; diff --git a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/PersistingEntityBuilderTest.java b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/PersistingEntityBuilderTest.java index 2b5a467f6..01f87eabb 100644 --- a/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/PersistingEntityBuilderTest.java +++ b/AMW_business/src/test/java/ch/puzzle/itc/mobiliar/test/PersistingEntityBuilderTest.java @@ -30,7 +30,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroupEntity; import ch.puzzle.itc.mobiliar.business.security.control.PermissionService; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.TemplatePropertyException; import ch.puzzle.itc.mobiliar.test.testrunner.PersistenceTestRunner; import org.junit.Before; @@ -76,7 +75,7 @@ public void before() { } @Test - public void testAmw() throws GeneralDBException { + public void testAmw() { builder = new PersistingEntityBuilder(entityManager).buildAmw(); assertEquals(16, builder.getResourceCount(ResourceEntity.class)); } diff --git a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/GeneralDBException.java b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/GeneralDBException.java deleted file mode 100644 index f3389035a..000000000 --- a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/GeneralDBException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * AMW - Automated Middleware allows you to manage the configurations of - * your Java EE applications on an unlimited number of different environments - * with various versions, including the automated deployment of those apps. - * Copyright (C) 2013-2016 by Puzzle ITC - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package ch.puzzle.itc.mobiliar.common.exception; - -import javax.ejb.ApplicationException; - -@ApplicationException(rollback=true) -public class GeneralDBException extends Exception{ - - // Diese Exception dient zum Markieren, falls ein command/Manipulation auf der DB fehlgeschlagen hat - - public static final String ERRORMESSAGE = "Something went wrong with the database access. Please contact your application administrator."; - - /** - * - */ - private static final long serialVersionUID = 1L; - - public GeneralDBException(String message, Throwable cause) { - super(message, cause); - } - - public GeneralDBException(String message) { - this(message, null); - } - - public String getErrorMessage(){ - return ERRORMESSAGE; - } - -} diff --git a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/NotFoundException.java b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/NotFoundException.java index 8966e96b1..a376c997c 100644 --- a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/NotFoundException.java +++ b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/NotFoundException.java @@ -20,6 +20,9 @@ package ch.puzzle.itc.mobiliar.common.exception; +/** + * General exception if an object isn't found in DB + */ public class NotFoundException extends AMWException { private static final long serialVersionUID = 1L; diff --git a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/PermissionNotFoundException.java b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/PermissionNotFoundException.java index 608fc57bf..595120999 100644 --- a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/PermissionNotFoundException.java +++ b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/PermissionNotFoundException.java @@ -20,7 +20,7 @@ package ch.puzzle.itc.mobiliar.common.exception; -public class PermissionNotFoundException extends AMWException{ +public class PermissionNotFoundException extends NotFoundException{ private static final long serialVersionUID = 1L; diff --git a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/PropertyTypeNotFoundException.java b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/PropertyTypeNotFoundException.java index bd23ac48e..37581f4b5 100644 --- a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/PropertyTypeNotFoundException.java +++ b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/PropertyTypeNotFoundException.java @@ -20,7 +20,7 @@ package ch.puzzle.itc.mobiliar.common.exception; -public class PropertyTypeNotFoundException extends AMWException{ +public class PropertyTypeNotFoundException extends NotFoundException{ private static final long serialVersionUID = 1L; diff --git a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ResourceNotFoundException.java b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ResourceNotFoundException.java index b79a5a307..9b6a546cd 100644 --- a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ResourceNotFoundException.java +++ b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ResourceNotFoundException.java @@ -20,12 +20,10 @@ package ch.puzzle.itc.mobiliar.common.exception; -public class ResourceNotFoundException extends AMWException { - // Wird geworfen, falls ein Löschen einer Resource auf der DB nicht möglich ist (f.ex. zu löschendes Item nicht existiert etc) - - /** - * - */ +/** + * Exception that is thrown if a resource isn't found. For other types use the general NotFoundException + */ +public class ResourceNotFoundException extends NotFoundException { private static final long serialVersionUID = 1L; public ResourceNotFoundException(String message){ diff --git a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ResourceTypeNotFoundException.java b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ResourceTypeNotFoundException.java index 155334676..60c3afda2 100644 --- a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ResourceTypeNotFoundException.java +++ b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ResourceTypeNotFoundException.java @@ -20,11 +20,8 @@ package ch.puzzle.itc.mobiliar.common.exception; -public class ResourceTypeNotFoundException extends AMWException { +public class ResourceTypeNotFoundException extends NotFoundException { - /** - * - */ private static final long serialVersionUID = 1L; public ResourceTypeNotFoundException(String message) { diff --git a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/ValidationException.java b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ValidationException.java similarity index 86% rename from AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/ValidationException.java rename to AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ValidationException.java index c33a66046..fe113572a 100644 --- a/AMW_business/src/main/java/ch/puzzle/itc/mobiliar/business/utils/ValidationException.java +++ b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/exception/ValidationException.java @@ -18,12 +18,15 @@ * along with this program. If not, see . */ -package ch.puzzle.itc.mobiliar.business.utils; +package ch.puzzle.itc.mobiliar.common.exception; import lombok.Getter; -public class ValidationException extends Exception { +/** + * Thrown it validation of an object/resource fails (string validation, business logic validation, etc.). + */ +public class ValidationException extends AMWException { /** * Use the causing object to pass information of failure diff --git a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/util/ConfigKey.java b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/util/ConfigKey.java index 758b6b9fa..74862e9d4 100644 --- a/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/util/ConfigKey.java +++ b/AMW_commons/src/main/java/ch/puzzle/itc/mobiliar/common/util/ConfigKey.java @@ -12,7 +12,7 @@ public enum ConfigKey { LOGS_PATH("amw.logsPath", "AMW_LOGSPATH", false), /** Age of logs to be deleted in minutes */ - LOGS_CLEANUP_AGE("amw.logsLeanupAge", "AMW_LOGSLEANUPAGE", new Integer(7*24*60).toString(), false), + LOGS_CLEANUP_AGE("amw.logsLeanupAge", "AMW_LOGSLEANUPAGE", Integer.valueOf(7*24*60).toString(), false), LOGS_CLEANUP_SCHEDULER_DISABLED("amw.logsCleanupSchedulerDisabled", "AMW_LOGSCLEANUPSCHEDULERDISABLED", "false", false), /** Path where the generator writes the files */ GENERATOR_PATH("amw.generatorPath", "AMW_GENERATORPATH", false), diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/Analyze/TestGenerationRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/Analyze/TestGenerationRest.java index edef2cdd6..828e654f6 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/Analyze/TestGenerationRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/Analyze/TestGenerationRest.java @@ -12,8 +12,8 @@ import ch.puzzle.itc.mobiliar.business.security.control.PermissionService; import ch.puzzle.itc.mobiliar.business.security.entity.Action; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import io.swagger.annotations.Api; import javax.inject.Inject; diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/RESTApplication.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/RESTApplication.java index 13e4a6b97..5299a032d 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/RESTApplication.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/RESTApplication.java @@ -71,8 +71,8 @@ private void addRestResourceClasses(Set> resources) { resources.add(NoResultExceptionMapper.class); resources.add(NotAuthorizedExceptionMapper.class); resources.add(ValidationExceptionMapper.class); + resources.add(NotFoundExceptionMapper.class); resources.add(UncaughtExceptionMapper.class); - resources.add(ResourceNotFoundExceptionMapper.class); resources.add(ServerTupleCSVBodyWriter.class); resources.add(HealthCheck.class); resources.add(SettingsRest.class); diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/auditview/AuditViewRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/auditview/AuditViewRest.java index d101f057b..88dc9f1ac 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/auditview/AuditViewRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/auditview/AuditViewRest.java @@ -3,7 +3,6 @@ import ch.mobi.itc.mobiliar.rest.dtos.AuditViewEntryDTO; import ch.puzzle.itc.mobiliar.business.auditview.boundary.AuditViewBoundary; import ch.puzzle.itc.mobiliar.business.property.boundary.PropertyEditor; -import ch.puzzle.itc.mobiliar.business.property.entity.ResourceEditProperty; import ch.puzzle.itc.mobiliar.business.auditview.entity.AuditViewEntry; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -60,12 +59,6 @@ public int compare(AuditViewEntryDTO o1, AuditViewEntryDTO o2) { }); } - private List removePropertyDescriptors(List propertiesForResourceIncludingDescriptors, List propertyDescriptors) { - ArrayList properties = new ArrayList<>(propertiesForResourceIncludingDescriptors); - properties.removeAll(propertyDescriptors); - return properties; - } - private List createDtosAndSortByTimestamp(List auditlogForResource) { List dtos = new ArrayList<>(auditlogForResource.size()); for (AuditViewEntry auditViewEntry : auditlogForResource) { diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/deployments/DeploymentsRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/deployments/DeploymentsRest.java index 0232a94c2..a63dde033 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/deployments/DeploymentsRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/deployments/DeploymentsRest.java @@ -596,9 +596,6 @@ public Response updateNodeJobResult( @ApiOperation(value = "Update the DeploymentDate of a Deployment - used by Angular") public Response changeDeploymentDate(@ApiParam("deployment Id") @PathParam("id") Integer deploymentId, @ApiParam("New date") long date) { Date newDate = new Date(date); - if (newDate == null) { - return Response.status(Response.Status.BAD_REQUEST).entity(new ExceptionDto("Invalid deployment date")).build(); - } try { deploymentBoundary.changeDeploymentDate(deploymentId, newDate); } catch (RuntimeException e) { diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/dtos/TemplateDTO.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/dtos/TemplateDTO.java index 9888f2fa4..a826ebda5 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/dtos/TemplateDTO.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/dtos/TemplateDTO.java @@ -38,6 +38,7 @@ @NoArgsConstructor public class TemplateDTO { + private Integer id; private String relatedResourceIdentifier; private String name; private String targetPath; @@ -45,12 +46,15 @@ public class TemplateDTO { private String fileContent; public TemplateDTO(TemplateDescriptorEntity template){ + this.id = template.getId(); this.relatedResourceIdentifier = template.getRelatedResourceIdentifier(); this.name = template.getName(); this.targetPath = template.getTargetPath(); targetPlatforms = new HashSet<>(); - for (ResourceGroupEntity pf : template.getTargetPlatforms()) { - targetPlatforms.add(pf.getName()); + if (template.getTargetPlatforms() != null) { + for (ResourceGroupEntity pf : template.getTargetPlatforms()) { + targetPlatforms.add(pf.getName()); + } } this.fileContent = template.getFileContent(); } diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/EJBExceptionMapper.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/EJBExceptionMapper.java index a4c1536e1..c980f38a2 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/EJBExceptionMapper.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/EJBExceptionMapper.java @@ -40,6 +40,6 @@ public Response toResponse(EJBException exception) { if (exceptionMapper != null) { return exceptionMapper.toResponse(causedByException); } - return Response.serverError().entity(causedByException).build(); + return Response.serverError().entity(exception).build(); } } diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ExceptionDto.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ExceptionDto.java index 1e0327f5d..37457d728 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ExceptionDto.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ExceptionDto.java @@ -29,7 +29,7 @@ public class ExceptionDto { private String detail; public ExceptionDto(String message) { - this(message, ""); + this(message, null); } public ExceptionDto(String message, String detail) { diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ResourceNotFoundExceptionMapper.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/NotFoundExceptionMapper.java similarity index 83% rename from AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ResourceNotFoundExceptionMapper.java rename to AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/NotFoundExceptionMapper.java index 95d9f5865..8a7bfba5a 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ResourceNotFoundExceptionMapper.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/NotFoundExceptionMapper.java @@ -24,13 +24,13 @@ import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; -import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.NotFoundException; @Provider -public class ResourceNotFoundExceptionMapper implements ExceptionMapper { +public class NotFoundExceptionMapper implements ExceptionMapper { @Override - public Response toResponse(ResourceNotFoundException exception) { + public Response toResponse(NotFoundException exception) { return Response.status(Response.Status.NOT_FOUND).entity(new ExceptionDto(exception)).build(); } } diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/UncaughtExceptionMapper.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/UncaughtExceptionMapper.java index 8530d82d3..0c4b51642 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/UncaughtExceptionMapper.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/UncaughtExceptionMapper.java @@ -1,33 +1,41 @@ -/* - * AMW - Automated Middleware allows you to manage the configurations of - * your Java EE applications on an unlimited number of different environments - * with various versions, including the automated deployment of those apps. - * Copyright (C) 2013-2016 by Puzzle ITC - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package ch.mobi.itc.mobiliar.rest.exceptions; - -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -@Provider -public class UncaughtExceptionMapper implements ExceptionMapper { - @Override - public Response toResponse(Throwable exception) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ExceptionDto(exception)).build(); - } -} +/* + * AMW - Automated Middleware allows you to manage the configurations of + * your Java EE applications on an unlimited number of different environments + * with various versions, including the automated deployment of those apps. + * Copyright (C) 2013-2016 by Puzzle ITC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package ch.mobi.itc.mobiliar.rest.exceptions; + +import javax.inject.Inject; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +import java.util.logging.Level; +import java.util.logging.Logger; + +@Provider +public class UncaughtExceptionMapper implements ExceptionMapper { + @Inject + private Logger log; + + @Override + public Response toResponse(Throwable exception) { + log.log(Level.SEVERE, "Uncaught exception in rest call", exception); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ExceptionDto("Internal Server Error", "See log file for details")).build(); + } +} diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ValidationExceptionMapper.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ValidationExceptionMapper.java index 2dedcfda4..974be31b7 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ValidationExceptionMapper.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/exceptions/ValidationExceptionMapper.java @@ -24,7 +24,7 @@ import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; @Provider public class ValidationExceptionMapper implements ExceptionMapper { diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/HostNamesRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/HostNamesRest.java index 9effebfc9..41d5b1ecc 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/HostNamesRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/HostNamesRest.java @@ -41,7 +41,7 @@ import ch.puzzle.itc.mobiliar.business.property.boundary.PropertyEditor; import ch.puzzle.itc.mobiliar.business.server.boundary.ServerView; import ch.puzzle.itc.mobiliar.business.server.entity.ServerTuple; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; @RequestScoped @Path("/hostNames") diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourcePropertiesRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourcePropertiesRest.java index cfb8f0ca3..d24f145b1 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourcePropertiesRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourcePropertiesRest.java @@ -46,7 +46,7 @@ import ch.puzzle.itc.mobiliar.business.property.entity.ResourceEditProperty; import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; @RequestScoped @Path("/resources/{resourceGroupName}/{releaseName}/properties") diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationPropertiesRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationPropertiesRest.java index 8d4a61934..338d508fc 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationPropertiesRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationPropertiesRest.java @@ -42,8 +42,7 @@ import ch.puzzle.itc.mobiliar.business.property.entity.ResourceEditProperty; import ch.puzzle.itc.mobiliar.business.resourcerelation.boundary.ResourceRelationLocator; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; - +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationTemplatesRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationTemplatesRest.java index c86d49798..f00c300bd 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationTemplatesRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationTemplatesRest.java @@ -39,9 +39,9 @@ import ch.puzzle.itc.mobiliar.business.template.boundary.TemplateEditor; import ch.puzzle.itc.mobiliar.business.template.control.TemplatesScreenDomainService; import ch.puzzle.itc.mobiliar.business.template.entity.TemplateDescriptorEntity; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; +import ch.puzzle.itc.mobiliar.common.exception.NotFoundException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; /** * Rest boundary for Resource-Relation-Templates @@ -68,42 +68,55 @@ public class ResourceRelationTemplatesRest { @GET @ApiOperation(value = "Get one or all templates for a resource in a specific release") - public List getResourceRelationTemplates( // - @PathParam("resourceGroupName") String resourceGroupName, - @PathParam("releaseName") String releaseName, - @PathParam("relatedResourceGroupName") String relatedResourceGroupName, - @PathParam("relatedReleaseName") String relatedReleaseName) throws ValidationException { - - return getResourceRelationTemplates(resourceGroupName, releaseName, relatedResourceGroupName, relatedReleaseName, ""); + public List getResourceRelationTemplates(@PathParam("resourceGroupName") String resourceGroupName, + @PathParam("releaseName") String releaseName, + @PathParam("relatedResourceGroupName") String relatedResourceGroupName, + @PathParam("relatedReleaseName") String relatedReleaseName) throws ValidationException, ResourceNotFoundException { + + List templates = getRelTemplates(resourceGroupName, releaseName, + relatedResourceGroupName, relatedReleaseName); + List templateDTOs = new ArrayList<>(); + for (TemplateDescriptorEntity template : templates) { + TemplateDTO temp = new TemplateDTO(template); + templateDTOs.add(temp); + } + return templateDTOs; } @GET @Path("/{templateName}") @ApiOperation(value = "Get one or all templates for a resource in a specific release") - public List getResourceRelationTemplates( // - @PathParam("resourceGroupName") String resourceGroupName, - @PathParam("releaseName") String releaseName, - @PathParam("relatedResourceGroupName") String relatedResourceGroupName, - @PathParam("relatedReleaseName") String relatedReleaseName, - @PathParam("templateName") String templateName) throws ValidationException { + public TemplateDTO getResourceRelationTemplate(@PathParam("resourceGroupName") String resourceGroupName, + @PathParam("releaseName") String releaseName, + @PathParam("relatedResourceGroupName") String relatedResourceGroupName, + @PathParam("relatedReleaseName") String relatedReleaseName, @PathParam("templateName") String templateName) + throws ValidationException, NotFoundException { + + List templates = getRelTemplates(resourceGroupName, releaseName, + relatedResourceGroupName, relatedReleaseName); + + for (TemplateDescriptorEntity template : templates) { + if (templateName.equals(template.getName())) { + return new TemplateDTO(template); + } + } + throw new NotFoundException("Template not found"); + } + + private List getRelTemplates(String resourceGroupName, String releaseName, + String relatedResourceGroupName, String relatedReleaseName) throws ValidationException, ResourceNotFoundException { List resRelList = resourceRelationLocator .getResourceRelationList(resourceGroupName, releaseName, relatedResourceGroupName, relatedReleaseName); List templates = new ArrayList<>(); for (ConsumedResourceRelationEntity resRel : resRelList) { - try { - List temp = templateService.getTemplatesForResourceRelation(resRel, false); - for (TemplateDescriptorEntity t : temp) { - t.setRelatedResourceIdentifier(resRel.getIdentifier()); - } - templates.addAll(temp); - } catch (ResourceNotFoundException | GeneralDBException e) { - // ignore + List temp = templateService.getTemplatesForResourceRelation(resRel, false); + for (TemplateDescriptorEntity t : temp) { + t.setRelatedResourceIdentifier(resRel.getIdentifier()); } + templates.addAll(temp); } - - return resourceTemplatesRest.getTemplateDTOs(templateName, templates); + return templates; } - } diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationsRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationsRest.java index 433621473..f1c725b91 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationsRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationsRest.java @@ -1,239 +1,239 @@ -/* - * AMW - Automated Middleware allows you to manage the configurations of - * your Java EE applications on an unlimited number of different environments - * with various versions, including the automated deployment of those apps. - * Copyright (C) 2013-2016 by Puzzle ITC - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package ch.mobi.itc.mobiliar.rest.resources; - -import ch.mobi.itc.mobiliar.rest.dtos.ResourceRelationDTO; -import ch.mobi.itc.mobiliar.rest.dtos.TemplateDTO; -import ch.mobi.itc.mobiliar.rest.exceptions.ExceptionDto; -import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwner; -import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwnerViolationException; -import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; -import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; -import ch.puzzle.itc.mobiliar.business.resourcerelation.boundary.RelationEditor; -import ch.puzzle.itc.mobiliar.business.resourcerelation.boundary.ResourceRelationLocator; -import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.AbstractResourceRelationEntity; -import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; -import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ProvidedResourceRelationEntity; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; -import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; -import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.apache.commons.lang3.StringUtils; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.ws.rs.*; -import javax.ws.rs.core.Response; -import java.util.*; - -import static javax.ws.rs.core.Response.Status.*; - -@RequestScoped -@Path("/resources/{resourceGroupName}/{releaseName}/relations") -@Api(value = "/resources/{resourceGroupName}/{releaseName}/relations", description = "Resource relations") -public class ResourceRelationsRest { - - @PathParam("resourceGroupName") - String resourceGroupName; - - @PathParam("releaseName") - String releaseName; - - @Inject - ResourceLocator resourceLocator; - - @Inject - ResourceRelationLocator resourceRelationLocator; - - @Inject - RelationEditor relationEditor; - - @Inject - ResourceRelationTemplatesRest resourceRelationTemplatesRest; - - @GET - @ApiOperation(value = "Get all relations of a resource in a specific release, optionally filtered by a slave resource type") - public List getResourceRelations(@ApiParam(value = "A String representing the type of the slave Resource") - @QueryParam("type") String resourceType) throws ValidationException { - return getResourceRelations(resourceGroupName, releaseName, resourceType); - } - - List getResourceRelations(String resourceGroupName, String releaseName, String resourceType) throws ValidationException { - ResourceEntity resource = resourceLocator.getResourceByNameAndReleaseWithAllRelations(resourceGroupName, releaseName); - List resourceRelations = new ArrayList<>(); - for (ConsumedResourceRelationEntity relation : resource.getConsumedMasterRelations()) { - ResourceRelationDTO resRel = createResourceRelationDTO(resourceGroupName, releaseName, resourceType, relation); - if (resRel != null) { - resourceRelations.add(resRel); - } - } - for (ProvidedResourceRelationEntity relation : resource.getProvidedMasterRelations()) { - ResourceRelationDTO resRel = createResourceRelationDTO(resourceGroupName, releaseName, resourceType, relation); - if (resRel != null) { - resourceRelations.add(resRel); - } - } - return resourceRelations; - } - - private ResourceRelationDTO createResourceRelationDTO(String resourceGroupName, String releaseName, String resourceType, AbstractResourceRelationEntity relation) throws ValidationException { - if (resourceType != null && !relation.getResourceRelationType().getResourceTypeB().getName().equals(resourceType)) { - return null; - } - ResourceRelationDTO resRel = new ResourceRelationDTO(relation); - List templates = resourceRelationTemplatesRest.getResourceRelationTemplates(resourceGroupName, releaseName, - relation.getSlaveResource().getName(), relation.getSlaveResource().getRelease().getName(), ""); - addTemplates(resRel, templates); - return resRel; - } - - @Path("/{relatedResourceGroupName}") - @GET - @ApiOperation(value = "Get all related releases of the given resource") - public List getRelatedResourcesForGroup( - @PathParam("relatedResourceGroupName") String relatedResourceGroupName) throws ValidationException { - List relations = - resourceRelationLocator.getRelatedResourcesForGroup(resourceGroupName, releaseName, relatedResourceGroupName); - List resourceRelations = new ArrayList<>(); - for (ConsumedResourceRelationEntity relation : relations) { - ResourceRelationDTO resRel = new ResourceRelationDTO(relation); - List templates = resourceRelationTemplatesRest.getResourceRelationTemplates(resourceGroupName, releaseName, - relatedResourceGroupName, relation.getSlaveResource().getRelease().getName(), ""); - addTemplates(resRel, templates); - resourceRelations.add(resRel); - } - return resourceRelations; - } - - // List of ResourceRelationDTO - @Path("/{relatedResourceGroupName}/{relatedReleaseName}") - @GET - @ApiOperation(value = "Get the list of relations between the two resource releases") - public List getResourceRelation(@PathParam("relatedResourceGroupName") String relatedResourceGroupName, - @PathParam("relatedReleaseName") String relatedReleaseName) throws ValidationException { - List list = new ArrayList<>(); - for (ConsumedResourceRelationEntity dto : resourceRelationLocator.getResourceRelationList(resourceGroupName, releaseName, - relatedResourceGroupName, relatedReleaseName)) { - ResourceRelationDTO resRel = new ResourceRelationDTO(dto); - List templates = resourceRelationTemplatesRest.getResourceRelationTemplates(resourceGroupName, releaseName, - relatedResourceGroupName, relatedReleaseName, ""); - addTemplates(resRel, templates); - list.add(resRel); - } - return list; - } - - /** - * Creates a new ResourceRelation - * - * @param slaveGroupName A String representing the name of an existing ResourceGroup which will be added as slave resource of the new ResourceRelation - * @param relationType A String representing the type of the Relation to be added - */ - @Path("/{slaveResourceGroupName}") - @POST - @ApiOperation(value = "Add a consumed or provided Relation") - public Response addRelation(@PathParam("slaveResourceGroupName") String slaveGroupName, - @ApiParam(value = "A String representing the type of the Relation", required = true) - @QueryParam("type") String relationType) { - if (StringUtils.isEmpty(slaveGroupName)) { - return Response.status(BAD_REQUEST).entity(new ExceptionDto("Slave resource group name must not be empty")).build(); - } else if (!relationEditor.isValidResourceRelationType(relationType)) { - return Response.status(BAD_REQUEST).entity(new ExceptionDto("Type must either be 'consumed' or 'provided'")).build(); - } - boolean isProvidedRelation = RelationEditor.ResourceRelationType.valueOf(relationType.toUpperCase()).equals(RelationEditor.ResourceRelationType.PROVIDED); - try { - relationEditor.addResourceRelationForSpecificRelease(resourceGroupName, slaveGroupName, - isProvidedRelation, null, relationType, releaseName, ForeignableOwner.getSystemOwner()); - } catch (ResourceNotFoundException | ElementAlreadyExistsException | ValidationException e) { - return Response.status(BAD_REQUEST).entity(new ExceptionDto(e.getMessage())).build(); - } - return Response.status(CREATED).build(); - } - - /** - * Removes a new ResourceRelation - * - * @param relationName A String representing the identifier of a Relation or the name of the related Resource to be removed - * @param relationType A String representing the type of the Relation to be removed - */ - @Path("/{relationName}") - @DELETE - @ApiOperation(value = "Remove a consumed or provided Relation from a specific Release", notes = "RelationName may be the identifier of a Relation or the name of the related Resource") - public Response removeRelation(@PathParam("relationName") String relationName, - @ApiParam(value = "A String representing the type of the Relation", required = true) - @QueryParam("type") String relationType) throws ValidationException { - if (StringUtils.isEmpty(relationName)) { - return Response.status(BAD_REQUEST).entity(new ExceptionDto("Relation name must not be empty")).build(); - } else if (!relationEditor.isValidResourceRelationType(relationType)) { - return Response.status(BAD_REQUEST).entity(new ExceptionDto("Type must either be 'consumed' or 'provided'")).build(); - } - RelationEditor.ResourceRelationType resourceRelationType = RelationEditor.ResourceRelationType.valueOf(relationType.toUpperCase()); - - Set relations = getRelations(resourceGroupName, releaseName, resourceRelationType); - - try { - if (relationEditor.removeMatchingRelation(relations, relationName)) { - return Response.status(Response.Status.OK).build(); - } else { - return Response.status(NOT_FOUND).entity(new ExceptionDto("No matching relation found")).build(); - } - - } catch (ForeignableOwnerViolationException fe) { - return Response.status(UNAUTHORIZED).entity(new ExceptionDto(fe.getMessage())).build(); - } catch (ResourceNotFoundException | ElementAlreadyExistsException e) { - return Response.status(NOT_FOUND).entity(new ExceptionDto(e.getMessage())).build(); - } - } - - private Set getRelations(String resourceGroupName, String releaseName, RelationEditor.ResourceRelationType resourceRelationType) throws ValidationException { - Set relations = new HashSet<>(); - if (resourceRelationType.equals(RelationEditor.ResourceRelationType.CONSUMED)) { - ResourceEntity resource = resourceLocator.getResourceByNameAndReleaseWithConsumedRelations(resourceGroupName, releaseName); - relations = resource.getConsumedMasterRelations(); - } else if (resourceRelationType.equals(RelationEditor.ResourceRelationType.PROVIDED)) { - ResourceEntity resource = resourceLocator.getResourceByNameAndReleaseWithProvidedRelations(resourceGroupName, releaseName); - relations = resource.getProvidedMasterRelations(); - } - return relations; - } - - private void addTemplates(ResourceRelationDTO resRel, List templates) { - List templatesToAdd = new ArrayList<>(); - for (TemplateDTO temp : templates) { - String tempName; - if (temp.getRelatedResourceIdentifier() == null) { - //eg standardJob - tempName = resRel.getRelatedResourceName(); - } else { - //eg standardJob_1 - tempName = resRel.getRelatedResourceName() + "_" + temp.getRelatedResourceIdentifier(); - } - if (tempName.equals(resRel.getRelationName())) { - templatesToAdd.add(temp); - } - } - resRel.setTemplates(new ArrayList()); - resRel.getTemplates().addAll(templatesToAdd); - } - -} +/* + * AMW - Automated Middleware allows you to manage the configurations of + * your Java EE applications on an unlimited number of different environments + * with various versions, including the automated deployment of those apps. + * Copyright (C) 2013-2016 by Puzzle ITC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package ch.mobi.itc.mobiliar.rest.resources; + +import ch.mobi.itc.mobiliar.rest.dtos.ResourceRelationDTO; +import ch.mobi.itc.mobiliar.rest.dtos.TemplateDTO; +import ch.mobi.itc.mobiliar.rest.exceptions.ExceptionDto; +import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwner; +import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwnerViolationException; +import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; +import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; +import ch.puzzle.itc.mobiliar.business.resourcerelation.boundary.RelationEditor; +import ch.puzzle.itc.mobiliar.business.resourcerelation.boundary.ResourceRelationLocator; +import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.AbstractResourceRelationEntity; +import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; +import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ProvidedResourceRelationEntity; +import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; +import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.apache.commons.lang3.StringUtils; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import java.util.*; + +import static javax.ws.rs.core.Response.Status.*; + +@RequestScoped +@Path("/resources/{resourceGroupName}/{releaseName}/relations") +@Api(value = "/resources/{resourceGroupName}/{releaseName}/relations", description = "Resource relations") +public class ResourceRelationsRest { + + @PathParam("resourceGroupName") + String resourceGroupName; + + @PathParam("releaseName") + String releaseName; + + @Inject + ResourceLocator resourceLocator; + + @Inject + ResourceRelationLocator resourceRelationLocator; + + @Inject + RelationEditor relationEditor; + + @Inject + ResourceRelationTemplatesRest resourceRelationTemplatesRest; + + @GET + @ApiOperation(value = "Get all relations of a resource in a specific release, optionally filtered by a slave resource type") + public List getResourceRelations(@ApiParam(value = "A String representing the type of the slave Resource") + @QueryParam("type") String resourceType) throws ValidationException, ResourceNotFoundException { + return getResourceRelations(resourceGroupName, releaseName, resourceType); + } + + List getResourceRelations(String resourceGroupName, String releaseName, String resourceType) throws ValidationException, ResourceNotFoundException { + ResourceEntity resource = resourceLocator.getResourceByNameAndReleaseWithAllRelations(resourceGroupName, releaseName); + List resourceRelations = new ArrayList<>(); + for (ConsumedResourceRelationEntity relation : resource.getConsumedMasterRelations()) { + ResourceRelationDTO resRel = createResourceRelationDTO(resourceGroupName, releaseName, resourceType, relation); + if (resRel != null) { + resourceRelations.add(resRel); + } + } + for (ProvidedResourceRelationEntity relation : resource.getProvidedMasterRelations()) { + ResourceRelationDTO resRel = createResourceRelationDTO(resourceGroupName, releaseName, resourceType, relation); + if (resRel != null) { + resourceRelations.add(resRel); + } + } + return resourceRelations; + } + + private ResourceRelationDTO createResourceRelationDTO(String resourceGroupName, String releaseName, String resourceType, AbstractResourceRelationEntity relation) throws ValidationException, ResourceNotFoundException { + if (resourceType != null && !relation.getResourceRelationType().getResourceTypeB().getName().equals(resourceType)) { + return null; + } + ResourceRelationDTO resRel = new ResourceRelationDTO(relation); + List templates = resourceRelationTemplatesRest.getResourceRelationTemplates(resourceGroupName, releaseName, + relation.getSlaveResource().getName(), relation.getSlaveResource().getRelease().getName()); + addTemplates(resRel, templates); + return resRel; + } + + @Path("/{relatedResourceGroupName}") + @GET + @ApiOperation(value = "Get all related releases of the given resource") + public List getRelatedResourcesForGroup( + @PathParam("relatedResourceGroupName") String relatedResourceGroupName) throws ValidationException, ResourceNotFoundException { + List relations = + resourceRelationLocator.getRelatedResourcesForGroup(resourceGroupName, releaseName, relatedResourceGroupName); + List resourceRelations = new ArrayList<>(); + for (ConsumedResourceRelationEntity relation : relations) { + ResourceRelationDTO resRel = new ResourceRelationDTO(relation); + List templates = resourceRelationTemplatesRest.getResourceRelationTemplates(resourceGroupName, releaseName, + relatedResourceGroupName, relation.getSlaveResource().getRelease().getName()); + addTemplates(resRel, templates); + resourceRelations.add(resRel); + } + return resourceRelations; + } + + // List of ResourceRelationDTO + @Path("/{relatedResourceGroupName}/{relatedReleaseName}") + @GET + @ApiOperation(value = "Get the list of relations between the two resource releases") + public List getResourceRelation(@PathParam("relatedResourceGroupName") String relatedResourceGroupName, + @PathParam("relatedReleaseName") String relatedReleaseName) throws ValidationException, ResourceNotFoundException { + List list = new ArrayList<>(); + for (ConsumedResourceRelationEntity dto : resourceRelationLocator.getResourceRelationList(resourceGroupName, releaseName, + relatedResourceGroupName, relatedReleaseName)) { + ResourceRelationDTO resRel = new ResourceRelationDTO(dto); + List templates = resourceRelationTemplatesRest.getResourceRelationTemplates(resourceGroupName, releaseName, + relatedResourceGroupName, relatedReleaseName); + addTemplates(resRel, templates); + list.add(resRel); + } + return list; + } + + /** + * Creates a new ResourceRelation + * + * @param slaveGroupName A String representing the name of an existing ResourceGroup which will be added as slave resource of the new ResourceRelation + * @param relationType A String representing the type of the Relation to be added + */ + @Path("/{slaveResourceGroupName}") + @POST + @ApiOperation(value = "Add a consumed or provided Relation") + public Response addRelation(@PathParam("slaveResourceGroupName") String slaveGroupName, + @ApiParam(value = "A String representing the type of the Relation", required = true) + @QueryParam("type") String relationType) { + if (StringUtils.isEmpty(slaveGroupName)) { + return Response.status(BAD_REQUEST).entity(new ExceptionDto("Slave resource group name must not be empty")).build(); + } else if (!relationEditor.isValidResourceRelationType(relationType)) { + return Response.status(BAD_REQUEST).entity(new ExceptionDto("Type must either be 'consumed' or 'provided'")).build(); + } + boolean isProvidedRelation = RelationEditor.ResourceRelationType.valueOf(relationType.toUpperCase()).equals(RelationEditor.ResourceRelationType.PROVIDED); + try { + relationEditor.addResourceRelationForSpecificRelease(resourceGroupName, slaveGroupName, + isProvidedRelation, null, relationType, releaseName, ForeignableOwner.getSystemOwner()); + } catch (ResourceNotFoundException | ElementAlreadyExistsException | ValidationException e) { + return Response.status(BAD_REQUEST).entity(new ExceptionDto(e.getMessage())).build(); + } + return Response.status(CREATED).build(); + } + + /** + * Removes a new ResourceRelation + * + * @param relationName A String representing the identifier of a Relation or the name of the related Resource to be removed + * @param relationType A String representing the type of the Relation to be removed + */ + @Path("/{relationName}") + @DELETE + @ApiOperation(value = "Remove a consumed or provided Relation from a specific Release", notes = "RelationName may be the identifier of a Relation or the name of the related Resource") + public Response removeRelation(@PathParam("relationName") String relationName, + @ApiParam(value = "A String representing the type of the Relation", required = true) + @QueryParam("type") String relationType) throws ValidationException { + if (StringUtils.isEmpty(relationName)) { + return Response.status(BAD_REQUEST).entity(new ExceptionDto("Relation name must not be empty")).build(); + } else if (!relationEditor.isValidResourceRelationType(relationType)) { + return Response.status(BAD_REQUEST).entity(new ExceptionDto("Type must either be 'consumed' or 'provided'")).build(); + } + RelationEditor.ResourceRelationType resourceRelationType = RelationEditor.ResourceRelationType.valueOf(relationType.toUpperCase()); + + Set relations = getRelations(resourceGroupName, releaseName, resourceRelationType); + + try { + if (relationEditor.removeMatchingRelation(relations, relationName)) { + return Response.status(Response.Status.OK).build(); + } else { + return Response.status(NOT_FOUND).entity(new ExceptionDto("No matching relation found")).build(); + } + + } catch (ForeignableOwnerViolationException fe) { + return Response.status(UNAUTHORIZED).entity(new ExceptionDto(fe.getMessage())).build(); + } catch (ResourceNotFoundException | ElementAlreadyExistsException e) { + return Response.status(NOT_FOUND).entity(new ExceptionDto(e.getMessage())).build(); + } + } + + private Set getRelations(String resourceGroupName, String releaseName, RelationEditor.ResourceRelationType resourceRelationType) throws ValidationException { + Set relations = new HashSet<>(); + if (resourceRelationType.equals(RelationEditor.ResourceRelationType.CONSUMED)) { + ResourceEntity resource = resourceLocator.getResourceByNameAndReleaseWithConsumedRelations(resourceGroupName, releaseName); + relations = resource.getConsumedMasterRelations(); + } else if (resourceRelationType.equals(RelationEditor.ResourceRelationType.PROVIDED)) { + ResourceEntity resource = resourceLocator.getResourceByNameAndReleaseWithProvidedRelations(resourceGroupName, releaseName); + relations = resource.getProvidedMasterRelations(); + } + return relations; + } + + private void addTemplates(ResourceRelationDTO resRel, List templates) { + List templatesToAdd = new ArrayList<>(); + for (TemplateDTO temp : templates) { + String tempName; + if (temp.getRelatedResourceIdentifier() == null) { + //eg standardJob + tempName = resRel.getRelatedResourceName(); + } else { + //eg standardJob_1 + tempName = resRel.getRelatedResourceName() + "_" + temp.getRelatedResourceIdentifier(); + } + if (tempName.equals(resRel.getRelationName())) { + templatesToAdd.add(temp); + } + } + resRel.setTemplates(new ArrayList()); + resRel.getTemplates().addAll(templatesToAdd); + } + +} diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTemplatesRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTemplatesRest.java index 9db36b63e..e115dacb1 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTemplatesRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTemplatesRest.java @@ -21,25 +21,31 @@ package ch.mobi.itc.mobiliar.rest.resources; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; +import javax.ws.rs.core.Response; import ch.mobi.itc.mobiliar.rest.dtos.TemplateDTO; -import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; -import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; -import ch.puzzle.itc.mobiliar.business.resourcerelation.boundary.ResourceRelationLocator; +import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceGroupLocator; +import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroupEntity; import ch.puzzle.itc.mobiliar.business.template.boundary.TemplateEditor; import ch.puzzle.itc.mobiliar.business.template.control.TemplatesScreenDomainService; import ch.puzzle.itc.mobiliar.business.template.entity.TemplateDescriptorEntity; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; +import ch.puzzle.itc.mobiliar.common.exception.AMWException; +import ch.puzzle.itc.mobiliar.common.exception.NotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.TemplateNotDeletableException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; /** * Rest boundary for Resource-Templates @@ -47,62 +53,116 @@ @RequestScoped @Path("/resources/{resourceGroupName}/{releaseName}/templates") @Api(value = "/resources/{resourceGroupName}/{releaseName}/templates", description = "Resource templates") -public class ResourceTemplatesRest { +public class ResourceTemplatesRest {; @Inject - ResourceLocator resourceLocator; + ResourceGroupLocator resourceGroupLocator; @Inject - ResourceRelationLocator resourceRelationLocator; + TemplatesScreenDomainService templateService; @Inject TemplateEditor templateEditor; - @Inject - TemplatesScreenDomainService templateService; - @GET - @ApiOperation(value = "Get one or all templates for a resource in a specific release") - public List getResourceTemplates( // - @PathParam("resourceGroupName") String resourceGroupName, - @PathParam("releaseName") String releaseName) throws ValidationException { - return getResourceTemplates(resourceGroupName, releaseName, ""); + @ApiOperation(value = "Get all templates for a resource in a specific release") + public List getResourceTemplates(@PathParam("resourceGroupName") String resourceGroupName, + @PathParam("releaseName") String releaseName) throws ValidationException { + List templateDTOs = new ArrayList<>(); + List templates = templateService.getGlobalTemplateDescriptorsForResource(resourceGroupName, releaseName, false); + + for (TemplateDescriptorEntity template : templates) { + TemplateDTO temp = new TemplateDTO(template); + templateDTOs.add(temp); + } + return templateDTOs; } @GET @Path("/{templateName}") - @ApiOperation(value = "Get one or all templates for a resource in a specific release") - public List getResourceTemplates( // - @PathParam("resourceGroupName") String resourceGroupName, - @PathParam("releaseName") String releaseName, - @PathParam("templateName") String templateName) throws ValidationException { + @ApiOperation(value = "Get a template for a resource in a specific release") + public TemplateDTO getResourceTemplate(@PathParam("resourceGroupName") String resourceGroupName, + @PathParam("releaseName") String releaseName, + @PathParam("templateName") String templateName) throws ValidationException, NotFoundException { + TemplateDescriptorEntity template = getTemplate(resourceGroupName, releaseName, templateName); + if (template == null) { + throw new NotFoundException("Template not found"); + } + return new TemplateDTO(template); + } + + @DELETE + @Path("/{templateName}") + @ApiOperation(value = "Delete a template for a resource in a specific release") + public Response deleteResourceTemplate(@PathParam("resourceGroupName") String resourceGroupName, + @PathParam("releaseName") String releaseName, + @PathParam("templateName") String templateName) throws ValidationException, AMWException { + try { + templateEditor.removeTemplate(resourceGroupName, releaseName, templateName, false); + } catch (TemplateNotDeletableException e) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } + return Response.status(Response.Status.OK).build(); + } - ResourceEntity resource = resourceLocator.getResourceByNameAndReleaseWithConsumedRelations(resourceGroupName, - releaseName); + @POST + @ApiOperation(value = "Create a template for a resource in a specific release") + public Response createResourceTemplates(@PathParam("resourceGroupName") String resourceGroupName, + @PathParam("releaseName") String releaseName, + TemplateDTO templateDTO) throws ValidationException, AMWException { + // make sure id isn't set or save will try to update the template + templateDTO.setId(null); + TemplateDescriptorEntity template = toTemplateDescriptorEntity(templateDTO, null); + + templateEditor.saveTemplateForResource(template, resourceGroupName, releaseName, false); + return Response.ok(new TemplateDTO(template)).build(); + } - List templates = templateService.getGlobalTemplateDescriptorsForResource(resource, - false); + @PUT + @Path("/{templateName}") + @ApiOperation(value = "Update a template for a resource in a specific release") + public Response updateResourceTemplates(@PathParam("resourceGroupName") String resourceGroupName, + @PathParam("releaseName") String releaseName, + @PathParam("templateName") String templateName, + TemplateDTO templateDTO) throws ValidationException, AMWException { + TemplateDescriptorEntity template = getTemplate(resourceGroupName, releaseName, templateName); + if (template == null) { + throw new NotFoundException("Template not found"); + } + template = toTemplateDescriptorEntity(templateDTO, template); - return getTemplateDTOs(templateName, templates); + templateEditor.saveTemplateForResource(template, resourceGroupName, releaseName, false); + return Response.ok(new TemplateDTO(template)).build(); } - public List getTemplateDTOs(String templateName, List templates) { - List result = new ArrayList<>(); - if ("".equals(templateName)) { - // all templates, but without file content - for (TemplateDescriptorEntity template : templates) { - TemplateDTO temp = new TemplateDTO(template); - temp.setFileContent(""); - result.add(temp); + private TemplateDescriptorEntity getTemplate(String resourceGroupName, String releaseName, String templateName) throws ValidationException { + List templates = templateService.getGlobalTemplateDescriptorsForResource(resourceGroupName, releaseName, false); + for (TemplateDescriptorEntity template : templates) { + if (templateName.equals(template.getName())) { + return template; } - } else { - for (TemplateDescriptorEntity template : templates) { - if (templateName.equals(template.getName())) { - TemplateDTO temp = new TemplateDTO(template); - result.add(temp); - } + } + return null; + } + + private TemplateDescriptorEntity toTemplateDescriptorEntity(TemplateDTO templateDTO, TemplateDescriptorEntity template) { + if (template == null) { + template = new TemplateDescriptorEntity(); + } + template.setId(templateDTO.getId()); + template.setTesting(false); + template.setFileContent(templateDTO.getFileContent()); + template.setName(templateDTO.getName()); + template.setTargetPath(templateDTO.getTargetPath()); + HashSet targetPlatforms = new HashSet<>(); + if (templateDTO.getTargetPlatforms() != null) { + for(String platform : templateDTO.getTargetPlatforms()) { + ResourceGroupEntity platformEntity = resourceGroupLocator.getResourceGroupByName(platform); + targetPlatforms.add(platformEntity); } } - return result; + template.setTargetPlatforms(targetPlatforms); + + return template; } } diff --git a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourcesRest.java b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourcesRest.java index 7359c86f9..3488c1cc0 100644 --- a/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourcesRest.java +++ b/AMW_rest/src/main/java/ch/mobi/itc/mobiliar/rest/resources/ResourcesRest.java @@ -46,10 +46,10 @@ import ch.puzzle.itc.mobiliar.business.security.boundary.PermissionBoundary; import ch.puzzle.itc.mobiliar.business.server.boundary.ServerView; import ch.puzzle.itc.mobiliar.business.server.entity.ServerTuple; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -188,11 +188,11 @@ public ResourceGroupDTO getResourceGroup(@PathParam("resourceGroupName") String public ResourceDTO getResource(@PathParam("resourceGroupName") String resourceGroupName, @PathParam("releaseName") String releaseName, @QueryParam("env") @DefaultValue("Global") String environment, - @QueryParam("type") String resourceType) throws ValidationException { + @QueryParam("type") String resourceType) throws ValidationException, ResourceNotFoundException { ResourceEntity resourceByRelease = resourceLocator.getResourceByGroupNameAndRelease(resourceGroupName, releaseName); return new ResourceDTO(resourceByRelease, resourceRelations.getResourceRelations(resourceGroupName, releaseName, resourceType), resourceProperties.getResourceProperties(resourceGroupName, releaseName, - environment), resourceTemplatesRest.getResourceTemplates(resourceGroupName, releaseName, "")); + environment), resourceTemplatesRest.getResourceTemplates(resourceGroupName, releaseName)); } @Path("/{resourceGroupName}/lte/{releaseName}") @@ -201,11 +201,11 @@ public ResourceDTO getResource(@PathParam("resourceGroupName") String resourceGr public ResourceDTO getExactOrClosestPastRelease(@PathParam("resourceGroupName") String resourceGroupName, @PathParam("releaseName") String releaseName, @QueryParam("env") @DefaultValue("Global") String environment, - @QueryParam("type") String resourceType) throws ValidationException { + @QueryParam("type") String resourceType) throws ValidationException, ResourceNotFoundException { ReleaseEntity release = resourceLocator.getExactOrClosestPastReleaseByGroupNameAndRelease(resourceGroupName, releaseName); return new ResourceDTO(release, resourceRelations.getResourceRelations(resourceGroupName, release.getName(), resourceType), resourceProperties.getResourceProperties(resourceGroupName, release.getName(), - environment), resourceTemplatesRest.getResourceTemplates(resourceGroupName, release.getName(), "")); + environment), resourceTemplatesRest.getResourceTemplates(resourceGroupName, release.getName())); } @Path("/resourceGroups") diff --git a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/Analyze/TestGenerationRestTest.java b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/Analyze/TestGenerationRestTest.java index 3620c0f41..26362c810 100644 --- a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/Analyze/TestGenerationRestTest.java +++ b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/Analyze/TestGenerationRestTest.java @@ -13,8 +13,9 @@ import ch.puzzle.itc.mobiliar.business.security.control.PermissionService; import ch.puzzle.itc.mobiliar.business.security.entity.Action; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; + import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatchers; diff --git a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/deployments/DeploymentTest.java b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/deployments/DeploymentTest.java index dce97e83a..95d10cafd 100644 --- a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/deployments/DeploymentTest.java +++ b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/deployments/DeploymentTest.java @@ -182,7 +182,6 @@ public void configure() { Mockito.any(DefaultResourceTypeDefinition.class), Mockito.any(ReleaseEntity.class))).thenAnswer(new Answer>() { @Override public Set answer(InvocationOnMock invocation) { - ResourceEntity appServer = (ResourceEntity)invocation.getArguments()[0]; HashSet set = new HashSet<>(); for(Application a : applicationServer.getAMWApplications()){ final String name = a.getName(); diff --git a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourcePropertiesRestTest.java b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourcePropertiesRestTest.java index 659c4125b..54098c08f 100644 --- a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourcePropertiesRestTest.java +++ b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourcePropertiesRestTest.java @@ -1,7 +1,8 @@ package ch.mobi.itc.mobiliar.rest.resources; import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; + import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; diff --git a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationPropertiesRestTest.java b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationPropertiesRestTest.java index 2610bc6b3..54d0134b6 100644 --- a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationPropertiesRestTest.java +++ b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationPropertiesRestTest.java @@ -26,7 +26,8 @@ import javax.ws.rs.core.Response; import ch.puzzle.itc.mobiliar.business.resourcerelation.boundary.ResourceRelationLocator; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; + import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; diff --git a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationsRestTest.java b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationsRestTest.java index 539011370..37a46a91b 100644 --- a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationsRestTest.java +++ b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceRelationsRestTest.java @@ -24,8 +24,9 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.boundary.RelationEditor; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; + import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; diff --git a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTemplatesRestTest.java b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTemplatesRestTest.java new file mode 100644 index 000000000..dad9c4e4c --- /dev/null +++ b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourceTemplatesRestTest.java @@ -0,0 +1,81 @@ +package ch.mobi.itc.mobiliar.rest.resources; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; + +import javax.ws.rs.core.Response; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import ch.mobi.itc.mobiliar.rest.dtos.TemplateDTO; +import ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceLocator; +import ch.puzzle.itc.mobiliar.business.template.boundary.TemplateEditor; +import ch.puzzle.itc.mobiliar.business.template.control.TemplatesScreenDomainService; +import ch.puzzle.itc.mobiliar.business.template.entity.TemplateDescriptorEntity; +import ch.puzzle.itc.mobiliar.common.exception.AMWException; +import ch.puzzle.itc.mobiliar.common.exception.NotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; + +public class ResourceTemplatesRestTest { + + @InjectMocks + private ResourceTemplatesRest resourceTemplatesRest; + + @Mock + private ResourceLocator resourceLocator; + + @Mock + private TemplateEditor templateEditor; + + @Mock + private TemplatesScreenDomainService templateService; + + @Before + public void configure() { + MockitoAnnotations.openMocks(this); + } + + @Test + public void idShouldBeResetOnCreateResourceTemplates() throws AMWException { + TemplateDTO templateDTO = new TemplateDTO(); + templateDTO.setId(123); + templateDTO.setName("test"); + + Response response = resourceTemplatesRest.createResourceTemplates("resourceGroupName", "releaseName", templateDTO); + + TemplateDTO result = (TemplateDTO) response.getEntity(); + assertNull(result.getId()); + assertEquals("test", result.getName()); + } + + @Test(expected = NotFoundException.class) + public void shouldRaisNotFoundExceptionOnGetResourceTemplate() throws ValidationException, NotFoundException { + resourceTemplatesRest.getResourceTemplate("resourceGroupName", "releaseName", "templateName"); + } + + @Test + public void shouldReturnCorrectTemplateOnOnGetResourceTemplate() throws ValidationException, NotFoundException { + ArrayList templates = new ArrayList<>(); + TemplateDescriptorEntity template = new TemplateDescriptorEntity(); + template.setName("template1"); + templates.add(template); + template = new TemplateDescriptorEntity(); + template.setName("template2"); + templates.add(template); + + when(templateService.getGlobalTemplateDescriptorsForResource(eq("resourceGroupName"), eq("releaseName"), eq(false))).thenReturn(templates); + + TemplateDTO templateDTO = resourceTemplatesRest.getResourceTemplate("resourceGroupName", "releaseName", "template2"); + + assertEquals("template2", templateDTO.getName()); + } + +} diff --git a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourcesRestTest.java b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourcesRestTest.java index ac476d7a1..2deaa5894 100644 --- a/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourcesRestTest.java +++ b/AMW_rest/src/test/java/ch/mobi/itc/mobiliar/rest/resources/ResourcesRestTest.java @@ -41,9 +41,10 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.common.exception.AMWException; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; +import ch.puzzle.itc.mobiliar.common.exception.NotFoundException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.exception.ResourceTypeNotFoundException; -import ch.puzzle.itc.mobiliar.common.util.DefaultResourceTypeDefinition; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import org.junit.Assert; import org.junit.Before; @@ -59,7 +60,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceTypeEntity; import ch.puzzle.itc.mobiliar.business.server.boundary.ServerView; import ch.puzzle.itc.mobiliar.business.server.entity.ServerTuple; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import javax.ws.rs.core.Response; @@ -340,7 +340,7 @@ public void shouldReturnBadRequestIfReleaseCreationFailed() throws AMWException, } @Test - public void shouldInvokeResourcesWithRightArgumentsOnGetClosestPastRelease() throws ValidationException { + public void shouldInvokeResourcesWithRightArgumentsOnGetClosestPastRelease() throws ValidationException, NotFoundException { // given String resourceGroupName = "TEST"; String releaseName = "RL-17.10"; @@ -356,7 +356,7 @@ public void shouldInvokeResourcesWithRightArgumentsOnGetClosestPastRelease() thr // then verify(resourceRelationsMock).getResourceRelations(resourceGroupName, closestRelease.getName(), resourceTypeName); verify(resourcePropertiesMock).getResourceProperties(resourceGroupName, closestRelease.getName(), env); - verify(resourceTemplatesRestMock).getResourceTemplates(resourceGroupName, closestRelease.getName(), ""); + verify(resourceTemplatesRestMock).getResourceTemplates(resourceGroupName, closestRelease.getName()); } @Test diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/Selected.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/Selected.java index 65ce45d11..91cc8c34b 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/Selected.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/Selected.java @@ -27,7 +27,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; -import javax.enterprise.inject.Stereotype; import javax.inject.Qualifier; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/applist/ApplistView.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/applist/ApplistView.java index 5bd42893a..e72f50276 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/applist/ApplistView.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/applist/ApplistView.java @@ -47,7 +47,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceWithRelations; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; import ch.puzzle.itc.mobiliar.common.exception.NotAuthorizedException; -import ch.puzzle.itc.mobiliar.common.exception.ResourceNotDeletableException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.common.util.DefaultResourceTypeDefinition; import ch.puzzle.itc.mobiliar.presentation.ViewBackingBean; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/common/ResourceTypeDataProvider.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/common/ResourceTypeDataProvider.java index 4a4125a7d..70c3a5e95 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/common/ResourceTypeDataProvider.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/common/ResourceTypeDataProvider.java @@ -41,7 +41,6 @@ import ch.puzzle.itc.mobiliar.common.exception.ResourceTypeNotFoundException; import ch.puzzle.itc.mobiliar.common.util.NameChecker; import ch.puzzle.itc.mobiliar.presentation.util.GlobalMessageAppender; -import ch.puzzle.itc.mobiliar.presentation.util.UserSettings; @SessionScoped @Named @@ -52,9 +51,6 @@ public class ResourceTypeDataProvider implements Serializable { @Inject private ResourceTypeDomainService domainService; - @Inject - private UserSettings userSettings; - @Inject protected Logger log; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/copyResource/CopyResourceDataProvider.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/copyResource/CopyResourceDataProvider.java index 57db8e8f4..b09f7ef01 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/copyResource/CopyResourceDataProvider.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/copyResource/CopyResourceDataProvider.java @@ -34,10 +34,8 @@ import ch.puzzle.itc.mobiliar.business.security.boundary.PermissionBoundary; import ch.puzzle.itc.mobiliar.business.utils.Identifiable; import ch.puzzle.itc.mobiliar.common.exception.AMWException; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException; import ch.puzzle.itc.mobiliar.presentation.common.ResourceTypeDataProvider; -import ch.puzzle.itc.mobiliar.presentation.propertyEdit.PropertyEditDataProvider; import ch.puzzle.itc.mobiliar.presentation.resourcesedit.EditResourceView; import ch.puzzle.itc.mobiliar.presentation.util.GlobalMessageAppender; import lombok.Getter; @@ -65,9 +63,6 @@ public class CopyResourceDataProvider implements Serializable { @Inject private CopyResource copyResource; - @Inject - private PropertyEditDataProvider propertyEditDataProvider; - @Inject private MaiaAmwFederationServicePredecessorHandler maiaAmwFederationServicePredecessorHandler; @@ -89,7 +84,7 @@ public class CopyResourceDataProvider implements Serializable { @Getter boolean loadList; - public void enableLoadList() throws GeneralDBException { + public void enableLoadList() { if(!loadList) { loadList = true; refreshResourceList(); @@ -111,8 +106,6 @@ public List getResourcesForSelectedResourceType() { /** * load resources for the selected type - * - * @throws GeneralDBException */ private void refreshResourceList() { resourceGroupMap = new HashMap<>(); @@ -163,8 +156,8 @@ public void copyFromPredecessorResource(Integer selectedGroup) { * @param resourceToOverwrite * @param copyFromResourceId * @return true if copy was successful, false otherwise - * @throws GeneralDBException * @throws ResourceNotFoundException + * @throws AMWException */ private boolean copyFromResourceAction(ResourceEntity resourceToOverwrite, Integer copyFromResourceId) throws AMWException, ForeignableOwnerViolationException { @@ -195,8 +188,6 @@ private boolean copyFromResourceAction(ResourceEntity resourceToOverwrite, Integ * @param resourceToOverwrite * @param predecessor * @return true if copy was successful, false otherwise - * @throws GeneralDBException - * @throws ResourceNotFoundException */ private boolean copyFromPredecessorResourceAction(ResourceEntity resourceToOverwrite, ResourceGroup predecessor) { if (resourceToOverwrite == null) { @@ -229,7 +220,6 @@ else if (predecessor == null) { * @param resourceTypeId * @param excludedList * @return - * @throws GeneralDBException */ public List loadResourcesForSelectedType(Integer resourceTypeId, List excludedList) { diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/dependencies/DependenciesController.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/dependencies/DependenciesController.java index 932b0a3b8..e5ed71ae5 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/dependencies/DependenciesController.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/dependencies/DependenciesController.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; @@ -35,12 +34,9 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ApplicationServer; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.control.ResourceRelationService; -import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.AbstractResourceRelationEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ProvidedResourceRelationEntity; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.presentation.resourceDependencies.DependencyModel; -import ch.puzzle.itc.mobiliar.presentation.util.GlobalMessageAppender; /** diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploy/CreateDeploymentController.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploy/CreateDeploymentController.java index 68aef1c07..67d204f3f 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploy/CreateDeploymentController.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploy/CreateDeploymentController.java @@ -182,7 +182,7 @@ executionDate, stateDate, deployParams, stringToIntegerList(contextIds), public List loadNewestDeploymentsPerAppserver(String... ids) { List deployments = new ArrayList<>(); - List idsAsString = (ids != null || ids.length > 0) ? Arrays.asList(ids) : new ArrayList(); + List idsAsString = ids != null ? Arrays.asList(ids) : new ArrayList(); for (String idString : idsAsString) { deployments.add(deploymentBoundary.getDeploymentById(Integer.valueOf(idString))); } diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploy/Domain.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploy/Domain.java index 2a397329a..dec2e3840 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploy/Domain.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploy/Domain.java @@ -21,7 +21,6 @@ package ch.puzzle.itc.mobiliar.presentation.deploy; import lombok.Getter; -import lombok.Setter; import javax.enterprise.event.Event; import java.util.ArrayList; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploymentparameter/DeploymentParameterView.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploymentparameter/DeploymentParameterView.java index 77d5ca5c9..52463ff44 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploymentparameter/DeploymentParameterView.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/deploymentparameter/DeploymentParameterView.java @@ -24,7 +24,7 @@ import ch.puzzle.itc.mobiliar.business.deploymentparameter.entity.Key; import ch.puzzle.itc.mobiliar.business.security.boundary.PermissionBoundary; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import ch.puzzle.itc.mobiliar.presentation.util.GlobalMessageAppender; import lombok.Getter; import lombok.Setter; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/foreignable/ForeignableOwnerTooltipCompositeBackingBean.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/foreignable/ForeignableOwnerTooltipCompositeBackingBean.java index 0e6e5ff17..0dee5b08c 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/foreignable/ForeignableOwnerTooltipCompositeBackingBean.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/foreignable/ForeignableOwnerTooltipCompositeBackingBean.java @@ -24,7 +24,6 @@ import javax.enterprise.context.RequestScoped; import javax.inject.Named; -import ch.puzzle.itc.mobiliar.business.foreignable.entity.Foreignable; import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwner; @Named diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/functionEdit/EditFunction.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/functionEdit/EditFunction.java index 10a1950b6..0d46540c8 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/functionEdit/EditFunction.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/functionEdit/EditFunction.java @@ -32,6 +32,7 @@ import ch.puzzle.itc.mobiliar.business.security.entity.Action; import ch.puzzle.itc.mobiliar.common.exception.NotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import lombok.Getter; import lombok.Setter; import ch.puzzle.itc.mobiliar.business.environment.entity.ContextEntity; @@ -42,7 +43,6 @@ import ch.puzzle.itc.mobiliar.business.security.boundary.PermissionBoundary; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; import ch.puzzle.itc.mobiliar.business.utils.Identifiable; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.presentation.CompositeBackingBean; import ch.puzzle.itc.mobiliar.presentation.common.context.SessionContext; import ch.puzzle.itc.mobiliar.presentation.resourceRelation.events.ChangeSelectedRelationEvent; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/functionEdit/EditFunctionView.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/functionEdit/EditFunctionView.java index a3531b911..42dbbb1e4 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/functionEdit/EditFunctionView.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/functionEdit/EditFunctionView.java @@ -35,8 +35,8 @@ import ch.puzzle.itc.mobiliar.business.function.boundary.FunctionsBoundary; import ch.puzzle.itc.mobiliar.business.function.entity.AmwFunctionEntity; import ch.puzzle.itc.mobiliar.business.security.boundary.PermissionBoundary; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import ch.puzzle.itc.mobiliar.presentation.ViewBackingBean; import ch.puzzle.itc.mobiliar.presentation.util.GlobalMessageAppender; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertyEdit/PropertyEditController.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertyEdit/PropertyEditController.java index 1487d8592..ab63e071c 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertyEdit/PropertyEditController.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertyEdit/PropertyEditController.java @@ -21,7 +21,6 @@ package ch.puzzle.itc.mobiliar.presentation.propertyEdit; import ch.puzzle.itc.mobiliar.business.foreignable.entity.ForeignableOwnerViolationException; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; import ch.puzzle.itc.mobiliar.common.util.NameChecker; import ch.puzzle.itc.mobiliar.presentation.resourceRelation.ResourceRelationModel; @@ -69,7 +68,7 @@ public void save() { GlobalMessageAppender.addErrorMessage(errorMessage); log.log(Level.SEVERE, errorMessage, e); } - catch (AMWException | ValidationException e) { + catch (AMWException e) { GlobalMessageAppender.addErrorMessage(e.getMessage()); log.log(Level.SEVERE, e.getMessage(), e); } diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertyEdit/PropertyEditDataProvider.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertyEdit/PropertyEditDataProvider.java index 428e3c86e..efb829666 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertyEdit/PropertyEditDataProvider.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertyEdit/PropertyEditDataProvider.java @@ -37,9 +37,8 @@ import ch.puzzle.itc.mobiliar.business.security.entity.Action; import ch.puzzle.itc.mobiliar.business.security.entity.Permission; import ch.puzzle.itc.mobiliar.business.softlinkRelation.boundary.SoftlinkRelationBoundary; -import ch.puzzle.itc.mobiliar.business.softlinkRelation.entity.SoftlinkRelationEntity; -import ch.puzzle.itc.mobiliar.business.utils.ValidationException; import ch.puzzle.itc.mobiliar.common.exception.AMWException; +import ch.puzzle.itc.mobiliar.common.exception.ValidationException; import ch.puzzle.itc.mobiliar.common.util.DefaultResourceTypeDefinition; import ch.puzzle.itc.mobiliar.presentation.CompositeBackingBean; import ch.puzzle.itc.mobiliar.presentation.Selected; @@ -332,10 +331,6 @@ private void preventDuplicateIdentifiers() throws AMWException { } } - private String getSoftlinkIdIfResource() { - return isCurrentFocusOnResource() ? ((ResourceEntity) resourceOrResourceType).getSoftlinkId() : null; - } - private String getNameOfResourceOrResourceType() { return resourceOrResourceType != null ? resourceOrResourceType.getName() : null; } diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertytype/PropertyTypeController.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertytype/PropertyTypeController.java index 0674de931..20361d5df 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertytype/PropertyTypeController.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/propertytype/PropertyTypeController.java @@ -34,7 +34,6 @@ import ch.puzzle.itc.mobiliar.business.property.control.PropertyTypeService; import ch.puzzle.itc.mobiliar.business.property.entity.PropertyTypeEntity; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.NotAuthorizedException; import ch.puzzle.itc.mobiliar.common.exception.PropertyTypeNotDeletableException; import ch.puzzle.itc.mobiliar.common.exception.PropertyTypeNotFoundException; @@ -133,9 +132,6 @@ public boolean doSave(Integer prtTypeId, String prtTypeName, String prtTypeValid GlobalMessageAppender.addErrorMessage("The property type has not been found."); } catch (RenameException e) { GlobalMessageAppender.addErrorMessage("Was not able to rename the property type."); - } catch (GeneralDBException e) { - String message = "Could not rename property type."; - GlobalMessageAppender.addErrorMessage(e.getErrorMessage() + " " + message); } catch (ElementAlreadyExistsException e) { GlobalMessageAppender.addErrorMessage("Was not able to save the property type."); } @@ -175,8 +171,6 @@ public boolean doCreateByPropertyType(String prtTypeName, String prtTypeValidati } } catch (ElementAlreadyExistsException e) { GlobalMessageAppender.addErrorMessage("Property type already exists."); - } catch (GeneralDBException e) { - GlobalMessageAppender.addErrorMessage(e.getErrorMessage() + " Could not create the new property type."); } return isSuccessful; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/release/ReleaseMgmtScreenService.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/release/ReleaseMgmtScreenService.java index 945743616..cb63a2609 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/release/ReleaseMgmtScreenService.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/release/ReleaseMgmtScreenService.java @@ -35,11 +35,9 @@ import ch.puzzle.itc.mobiliar.business.deploy.boundary.DeploymentBoundary; import ch.puzzle.itc.mobiliar.business.releasing.boundary.ReleaseLocator; import ch.puzzle.itc.mobiliar.business.releasing.control.ReleaseMgmtService; -import ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentEntity; import ch.puzzle.itc.mobiliar.business.releasing.entity.ReleaseEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceTypeEntity; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.presentation.components.impl.PaginationComp; import ch.puzzle.itc.mobiliar.presentation.util.GlobalMessageAppender; @@ -118,7 +116,6 @@ public boolean isDefaultRelease(ReleaseEntity release){ private ReleaseEntity currentRelease; private SortedMap> resourcesForCurrentRelease; - private List deploymentsForCurrentRelease; public void remove(){ releaseLocator.delete(currentRelease); @@ -159,8 +156,6 @@ public void loadResourcesAndDeploymentsForRelease(Integer releaseId) { } resourcesForCurrentRelease.get(r.getResourceType()).add(r); } - deploymentsForCurrentRelease = deploymentBoundary - .getDeploymentsForRelease(releaseId); } public boolean hasResourcesForCurrentRelease() { @@ -190,21 +185,15 @@ public List getResForCurrentReleaseByType(Integer typeId) { * Stores the release with the corresponding service method. Please call during edit- or create-form submission. */ public boolean save() { - try { - if (currentRelease.getId() == null) { - releaseMgmtService.create(currentRelease); - } else { - releaseMgmtService.update(currentRelease); - } - GlobalMessageAppender.addSuccessMessage("Release " + currentRelease.getName() - + " successfully saved."); - reload(); - return true; - } catch (GeneralDBException e) { - String message = "The selected resource can not be found."; - GlobalMessageAppender.addErrorMessage(message); - return false; + if (currentRelease.getId() == null) { + releaseMgmtService.create(currentRelease); + } else { + releaseMgmtService.update(currentRelease); } + GlobalMessageAppender.addSuccessMessage("Release " + currentRelease.getName() + + " successfully saved."); + reload(); + return true; } @Override diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceDependencies/DependencyModel.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceDependencies/DependencyModel.java index 09297c796..2d6c7de87 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceDependencies/DependencyModel.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceDependencies/DependencyModel.java @@ -22,9 +22,7 @@ import java.io.Serializable; -import lombok.Setter; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.AbstractResourceRelationEntity; -import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; /** * UI model for displaying resource dependencies diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceDependencies/events/SelectedResourceEvent.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceDependencies/events/SelectedResourceEvent.java index 5cc374b58..9a0a3260b 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceDependencies/events/SelectedResourceEvent.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceDependencies/events/SelectedResourceEvent.java @@ -23,7 +23,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; /** * This is an event container for notification of observers that another resource has been selected on the gui. If no resource has been selected, the corresponding relation field is null. diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceRelations/ResourceRelations.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceRelations/ResourceRelations.java index 10bdd025c..ce5f3ee4b 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceRelations/ResourceRelations.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourceRelations/ResourceRelations.java @@ -24,7 +24,6 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import java.util.Map; import javax.enterprise.event.Observes; import javax.inject.Inject; @@ -34,7 +33,6 @@ import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ApplicationServer; import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.control.ResourceRelationService; -import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.AbstractResourceRelationEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ConsumedResourceRelationEntity; import ch.puzzle.itc.mobiliar.business.resourcerelation.entity.ProvidedResourceRelationEntity; import ch.puzzle.itc.mobiliar.business.softlinkRelation.boundary.DisplaySoftlinkDependencies; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourcesedit/events/SelectedRelationId.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourcesedit/events/SelectedRelationId.java index 0302df571..cd3c2fcc2 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourcesedit/events/SelectedRelationId.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/resourcesedit/events/SelectedRelationId.java @@ -27,9 +27,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; -import javax.enterprise.inject.Stereotype; -import javax.faces.bean.ViewScoped; -import javax.inject.Named; import javax.inject.Qualifier; diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/server/ServerListView.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/server/ServerListView.java index 9b07dfc65..107733dfe 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/server/ServerListView.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/server/ServerListView.java @@ -34,7 +34,6 @@ import ch.puzzle.itc.mobiliar.business.server.boundary.ServerView; import ch.puzzle.itc.mobiliar.business.server.entity.ServerTuple; import ch.puzzle.itc.mobiliar.business.utils.JpaWildcardConverter; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.util.ConfigurationService; import ch.puzzle.itc.mobiliar.common.util.DefaultResourceTypeDefinition; import ch.puzzle.itc.mobiliar.common.util.ConfigKey; @@ -83,7 +82,7 @@ public class ServerListView implements Serializable { private boolean resourceReadPermission; // called by preRenderView event - public void init() throws GeneralDBException { + public void init() { //cache permissions in view this.appServerReadPermission = securityDataProvider.hasPermissionForResourceType("RESOURCE", "READ", "APPLICATIONSERVER"); this.resourceReadPermission = securityDataProvider.hasPermission("RESOURCE", "READ"); @@ -101,7 +100,7 @@ public String getFILTER_TOOLTIP() { return FILTER_TOOLTIP; } - public void loadRuntimes() throws GeneralDBException { + public void loadRuntimes() { runtimes = commonServcie.getRuntimeResourceGroups(); } diff --git a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/shakedownstp/ShakedownStpDataProvider.java b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/shakedownstp/ShakedownStpDataProvider.java index c967a01a1..f2607044d 100644 --- a/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/shakedownstp/ShakedownStpDataProvider.java +++ b/AMW_web/src/main/java/ch/puzzle/itc/mobiliar/presentation/shakedownstp/ShakedownStpDataProvider.java @@ -33,9 +33,9 @@ import ch.puzzle.itc.mobiliar.business.shakedown.control.ShakedownStpService; import ch.puzzle.itc.mobiliar.business.shakedown.entity.ShakedownStpEntity; import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException; -import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException; import ch.puzzle.itc.mobiliar.common.exception.NotAuthorizedException; import ch.puzzle.itc.mobiliar.common.exception.StpNotFoundException; +import ch.puzzle.itc.mobiliar.common.exception.TemplateNotDeletableException; import ch.puzzle.itc.mobiliar.common.util.ConfigurationService; import ch.puzzle.itc.mobiliar.common.util.ConfigKey; import ch.puzzle.itc.mobiliar.presentation.CompositeBackingBean; @@ -155,7 +155,7 @@ public List getStp() { return stp; } - public void deleteSTP() { + public void deleteSTP() throws TemplateNotDeletableException { deleteSTP(currentSTPSelected().getId()); loadStps(); } @@ -313,7 +313,7 @@ private boolean createNewSTP(String newSTPName, String newSTPVersion, List