Skip to content

Commit

Permalink
Merge pull request #618 from liimaorg/rest_update_template
Browse files Browse the repository at this point in the history
Implement REST update Resource Template
  • Loading branch information
yvespp authored Jul 26, 2021
2 parents 5869818 + 3c48618 commit 6599d03
Show file tree
Hide file tree
Showing 154 changed files with 810 additions and 995 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,39 +214,4 @@ public void setResourceIdInThreadLocal(Integer resourceId) {
ThreadLocalUtil.setThreadVariable(ThreadLocalUtil.KEY_RESOURCE_ID, resourceId);
}

/**
* @return a list of three-element arrays, containing:
* <ol>
* <li>the entity instance</li>
* <li>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}</li>
* <li>type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})</li>
* </ol>
*/
private <T> 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<T>) 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());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import javax.persistence.Query;
import javax.persistence.Table;

import ch.puzzle.itc.mobiliar.common.exception.GeneralDBException;

public class QueryUtils {


Expand All @@ -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 <T> List<T> fetch(Class<T> clazz, Query query, int start, int length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -50,9 +49,6 @@ public class DeploymentExecuterService {
@Inject
private LockingService lockingService;

@Inject
private EntityManager entityManager;

@Inject
private DeploymentAsynchronousExecuter deploymentAsynchronousExecuter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -65,15 +66,18 @@ public class CustomFilter {

@Setter
@Getter
@Default
private List<String> dropDownItems = new ArrayList<>();

@Setter
@Getter
@Default
private Map<String, String> dropDownItemsMap = new HashMap<>();

@Setter
private Class<? extends Enum> enumType;

@Default
private Object value = null;

private Long filterIdentifikationNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,7 +44,6 @@ public ContextEntity getContextByName(String name){
* Returns all Environments
*
* @return
* @throws GeneralDBException
*/
public List<ContextEntity> getEnvironments() {
return QueryUtils.fetch(ContextEntity.class, fetchAllContexts(), 0, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,25 +548,6 @@ public static Map<PropertyDescriptorEntity, List<PropertyEntity>> 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<TemplateDescriptorEntity> getTemplates(ContextEntity context, Set<TemplateDescriptorEntity> result) {
if (result == null) {
result = new HashSet<>();
}
getTemplatesForContext(context, result);
if (context.getParent() != null) {
result = getTemplates(context.getParent(), result);
}
return result;
}

private static Set<PropertyDescriptorEntity> getPropertyDescriptors(ContextEntity context, Set<PropertyDescriptorEntity> result) {
if (result == null) {
result = new HashSet<>();
Expand All @@ -578,10 +559,6 @@ private static Set<PropertyDescriptorEntity> getPropertyDescriptors(ContextEntit
return result;
}

private static void getTemplatesForContext(ContextEntity context, Set<TemplateDescriptorEntity> result) {
collectTemplateDescriptors(context, result);
}

private static void getPropertyDescriptorsForContext(ContextEntity context, Set<PropertyDescriptorEntity> result) {
Set<PropertyDescriptorEntity> properties = context.getPropertyDescriptors();
if (properties != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -296,12 +294,6 @@ private void logStartTemplateGeneration(TemplateDescriptorEntity template) {
log.finest("started: " + template.toString());
}

private void logBeforeException(TemplateException te, Map<String, Object> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,9 +73,6 @@ public class MaiaAmwFederationServicePredecessorHandler {
@Inject
ForeignableService foreignableService;

@Inject
private ResourceImportService resourceImportService;

@Inject
private ResourceRelationService resourceRelationService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package ch.puzzle.itc.mobiliar.business.predecessor.entity;

import lombok.Getter;
import lombok.Setter;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 6599d03

Please sign in to comment.