Skip to content

Commit

Permalink
Upgrade to Java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
RHarryH committed Dec 2, 2023
1 parent 575a113 commit e1e63d7
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 145 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<java.version>17</java.version>
<jodconverter.version>4.4.6</jodconverter.version>
<mapstruct.version>1.6.0.Beta1</mapstruct.version>
<sonar.skip>true</sonar.skip>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/avispa/ecm/model/EcmEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public Content getPrimaryContent() {

@Override
public final boolean equals(Object that) {
return this == that || that instanceof EcmEntity
&& Objects.equals(id, ((EcmEntity) that).id);
return this == that || that instanceof EcmEntity thatEntity
&& Objects.equals(id, thatEntity.id);
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/avispa/ecm/model/EcmObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@EntityListeners(AuditingEntityListener.class)
@Getter
public abstract class EcmObject extends EcmEntity {

@Getter
@CreatedDate
private LocalDateTime creationDate;

@Getter
@LastModifiedDate
private LocalDateTime modificationDate;

@Getter
@Setter
@OneToOne(fetch = FetchType.LAZY)
private Folder folder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import javax.persistence.ManyToOne;
import javax.validation.constraints.PositiveOrZero;
import java.util.List;
import java.util.stream.Collectors;

/**
* Contexts importance (for the time being) is based on the insertion order. The context algorithm will search for all
Expand Down Expand Up @@ -59,6 +58,6 @@ public class Context extends EcmConfig {
private int importance; // higher = more important

public void setEcmConfigs(List<EcmConfig> ecmConfigs) {
this.ecmConfigs = ecmConfigs.stream().filter(config -> !(config instanceof Context)).collect(Collectors.toList());
this.ecmConfigs = ecmConfigs.stream().filter(config -> !(config instanceof Context)).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public <T extends EcmObject> List<EcmConfig> getConfigurations(T object) {
.collect(Collectors.groupingBy(EcmConfig::getClass)) // group by class name
.values().stream()
.map(list -> list.get(0))// for each list get only first element
.collect(Collectors.toList());
.toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Configuration read(Path zipConfigPath) {
}

Configuration config = new Configuration();
try(FileSystem fileSystem = FileSystems.newFileSystem(zipConfigPath, null)) {
try (FileSystem fileSystem = FileSystems.newFileSystem(zipConfigPath, (ClassLoader) null)) {
for(var configType : configurationRegistry) {
Path configPath = fileSystem.getPath(configType.getName());
processDirectory(configType, config, configPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.avispa.ecm.model.type.Type;
import com.avispa.ecm.model.type.TypeService;
import com.avispa.ecm.util.exception.RepositoryCorruptionError;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
Expand All @@ -39,7 +40,8 @@
/**
* @author Rafał Hiszpański
*/
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE)
public abstract class ContextMapper implements EcmConfigMapper<Context, ContextDto> {
@Autowired
private EcmConfigRepository<EcmConfig> ecmConfigRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,15 @@ private Optional<PropertyPageContent> getPropertyPageContent(Content content) {

private void processControls(List<Control> controls, Object context) {
for(Control control : controls) {
if(control instanceof Columns) {
Columns columns = (Columns) control;
if (control instanceof Columns columns) {
processControls(columns.getControls(), context);
} else if(control instanceof Group) {
Group group = (Group) control;
} else if (control instanceof Group group) {
processControls(group.getControls(), context);
} else if(control instanceof Tabs) {
Tabs tabs = (Tabs)control;
} else if (control instanceof Tabs tabs) {
for(Tab tab : tabs.getTabs()) {
processControls(tab.getControls(), context);
}
} else if(control instanceof Table) {
Table table = (Table)control;
} else if (control instanceof Table table) {
tableMapper.processControl(table, context);
} else {
simpleControlMapper.processControl(control, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,19 @@ class SimpleControlMapper extends BaseControlsMapper<Control> {
}

public void processControl(Control control, Object context) {
if(control instanceof Label) {
Label label = (Label)control;
if (control instanceof Label label) {
try {
label.setExpression(expressionResolver.resolve(context, label.getExpression()));
} catch (ExpressionResolverException e) {
log.error("Label expression couldn't be resolved", e);
}
} else if(control instanceof PropertyControl) {
} else if (control instanceof PropertyControl propertyControl) {
// TODO: validate if property is accessible?
PropertyControl propertyControl = (PropertyControl) control;
if(Strings.isEmpty(propertyControl.getLabel())) {
propertyControl.setLabel(displayService.getDisplayValueFromAnnotation(context.getClass(), propertyControl.getProperty()));
}

if(control instanceof ComboRadio) {
ComboRadio comboRadio = (ComboRadio) control;
if (control instanceof ComboRadio comboRadio) {
try {
if (StringUtils.isEmpty(comboRadio.getTypeName()) && StringUtils.isNotEmpty(comboRadio.getTypeNameExpression())) {
comboRadio.setTypeName(expressionResolver.resolve(context, comboRadio.getTypeNameExpression()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ private Class<?> getTableRowClass(Table table, Class<?> contextClass) {
if(field != null && field.getType().isAssignableFrom(List.class)) {
java.lang.reflect.Type genericFieldType = field.getGenericType();

if (genericFieldType instanceof ParameterizedType) {
ParameterizedType aType = (ParameterizedType) genericFieldType;
java.lang.reflect.Type[] fieldArgTypes = aType.getActualTypeArguments();
if (genericFieldType instanceof ParameterizedType parameterizedType) {
java.lang.reflect.Type[] fieldArgTypes = parameterizedType.getActualTypeArguments();
if(fieldArgTypes.length > 0) {
Class<?> rowClass = (Class<?>) fieldArgTypes[0];
log.debug("Found table type class: '{}'", rowClass);
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/com/avispa/ecm/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,16 @@
package com.avispa.ecm.util;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;

/**
* @author Rafał Hiszpański
*/
@Getter
public class Version {
private final String componentName;
private final String number;

public Version(String componentName, String number) {
this.componentName = componentName;
this.number = number;
}
public record Version(String componentName, String number) {

@JsonIgnore
public String getReleaseNumber() {
int index = this.number.indexOf('-');
if(index != -1) {
if (index != -1) {
return this.number.substring(0, index);
}
return this.number;
Expand Down
38 changes: 16 additions & 22 deletions src/main/java/com/avispa/ecm/util/condition/ConditionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,36 +179,30 @@ private Condition parseConditions(String key, JsonNode value) {

private Condition processValue(String key, Operator operator, JsonNode value) {
ConditionValue<?> conditionValue = getConditionValue(value);
switch(operator) {
case EQ:
return Condition.equal(key, conditionValue);
case NE:
return Condition.notEqual(key, conditionValue);
case GT:
return Condition.greaterThan(key, conditionValue);
case GTE:
return Condition.greaterThanOrEqual(key, conditionValue);
case LT:
return Condition.lessThan(key, conditionValue);
case LTE:
return Condition.lessThanOrEqual(key, conditionValue);
}
return switch (operator) {
case EQ -> Condition.equal(key, conditionValue);
case NE -> Condition.notEqual(key, conditionValue);
case GT -> Condition.greaterThan(key, conditionValue);
case GTE -> Condition.greaterThanOrEqual(key, conditionValue);
case LT -> Condition.lessThan(key, conditionValue);
case LTE -> Condition.lessThanOrEqual(key, conditionValue);
};

return null;
}

private ConditionValue<?> getConditionValue(JsonNode value) {
JsonNodeType nodeType = value.getNodeType();
switch(nodeType) {
case STRING:
switch (nodeType) {
case STRING -> {
return ConditionValue.text(value.textValue());
case BOOLEAN:
}
case BOOLEAN -> {
return ConditionValue.bool(value.booleanValue());
case NUMBER:
}
case NUMBER -> {
return ConditionValue.number(value.numberValue());
default:
log.debug("Unsupported node type: {}", nodeType);
break;
}
default -> log.debug("Unsupported node type: {}", nodeType);
}
return null;
}
Expand Down
57 changes: 18 additions & 39 deletions src/main/java/com/avispa/ecm/util/condition/ConditionResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,60 +113,39 @@ private List<Predicate> getPredicates(Conditions conditions, CriteriaBuilder cri
private List<Predicate> resolveGroup(CriteriaBuilder criteriaBuilder, Root<? extends EcmObject> queryRoot, ConditionGroup group) {
List<Predicate> predicates = new ArrayList<>(group.getConditions().size());
for (IConditionElement element : group.getConditions()) {
if(element instanceof ConditionGroup) {
ConditionGroup nestedGroup = (ConditionGroup) element;
if (element instanceof ConditionGroup nestedGroup) {
List<Predicate> groupPredicates = resolveGroup(criteriaBuilder, queryRoot, nestedGroup);

Predicate predicate = getPredicate(nestedGroup.getGroupType(), criteriaBuilder, groupPredicates);
predicates.add(predicate);

} else if(element instanceof Condition) {
Condition condition = (Condition) element;

} else if (element instanceof Condition condition) {
predicates.add(getPredicate(condition, criteriaBuilder, queryRoot));
}
}
return predicates;
}

private Predicate getPredicate(GroupType groupType, CriteriaBuilder criteriaBuilder, List<Predicate> groupPredicates) {
switch(groupType) {
case AND:
return criteriaBuilder.and(groupPredicates.toArray(new Predicate[0]));
case OR:
return criteriaBuilder.or(groupPredicates.toArray(new Predicate[0]));
default:
if(log.isWarnEnabled()) {
log.warn("Unknown group type: {}", groupType);
}
return null;
}
return switch (groupType) {
case AND -> criteriaBuilder.and(groupPredicates.toArray(new Predicate[0]));
case OR -> criteriaBuilder.or(groupPredicates.toArray(new Predicate[0]));
};
}

private Predicate getPredicate(Condition condition, CriteriaBuilder criteriaBuilder, Root<? extends EcmObject> queryRoot) {
String key = condition.getKey();
Operator operator = condition.getOperator();
ConditionValue<?> value = condition.getValue();

switch(operator) {
case EQ:
return criteriaBuilder.equal(getPath(key, queryRoot), value.getValue());
case NE:
return criteriaBuilder.notEqual(getPath(key, queryRoot), value.getValue());
case GT:
return criteriaBuilder.gt(getPath(key, queryRoot), (Number) value.getValue());
case GTE:
return criteriaBuilder.ge(getPath(key, queryRoot), (Number) value.getValue());
case LT:
return criteriaBuilder.lt(getPath(key, queryRoot), (Number) value.getValue());
case LTE:
return criteriaBuilder.le(getPath(key, queryRoot), (Number) value.getValue());
default:
if(log.isWarnEnabled()) {
log.warn("Unknown operator: {}", operator);
}
return null;
}
String key = condition.key();
Operator operator = condition.operator();
ConditionValue<?> value = condition.value();

return switch (operator) {
case EQ -> criteriaBuilder.equal(getPath(key, queryRoot), value.getValue());
case NE -> criteriaBuilder.notEqual(getPath(key, queryRoot), value.getValue());
case GT -> criteriaBuilder.gt(getPath(key, queryRoot), (Number) value.getValue());
case GTE -> criteriaBuilder.ge(getPath(key, queryRoot), (Number) value.getValue());
case LT -> criteriaBuilder.lt(getPath(key, queryRoot), (Number) value.getValue());
case LTE -> criteriaBuilder.le(getPath(key, queryRoot), (Number) value.getValue());
};
}

private <Y> Path<Y> getPath(String key, Root<? extends EcmObject> queryRoot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@

import com.avispa.ecm.util.condition.Operator;
import com.avispa.ecm.util.condition.intermediate.value.ConditionValue;
import lombok.Value;

/**
* @author Rafał Hiszpański
*/
@Value
public class Condition implements IConditionElement {
String key;
Operator operator;
ConditionValue<?> value;

public record Condition(String key, Operator operator, ConditionValue<?> value) implements IConditionElement {
public static Condition equal(String key, ConditionValue<?> value) {
return new Condition(key, Operator.EQ, value);
}
Expand Down
21 changes: 7 additions & 14 deletions src/main/java/com/avispa/ecm/util/expression/FunctionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,15 @@ private FunctionFactory() {
public static String resolve(String functionName, String[] functionParams, Object object) {
Function function;

switch(functionName) {
case VALUE_FUNCTION:
function = new Value();
break;
case DATEVALUE_FUNCTION:
function = new DateValue();
break;
case DEFAULT_FUNCTION:
function = new Default();
break;
case PAD_FUNCTION:
function = new Pad();
break;
default:
switch (functionName) {
case VALUE_FUNCTION -> function = new Value();
case DATEVALUE_FUNCTION -> function = new DateValue();
case DEFAULT_FUNCTION -> function = new Default();
case PAD_FUNCTION -> function = new Pad();
default -> {
log.error("Unknown function '{}'", functionName);
return null;
}
}

return resolveFunction(object, functionParams, function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ public String resolve(Object object, String[] params) {
private String getValue(Object object, String propertyName, String format) {
Object value = PropertyUtils.getPropertyValue(object, propertyName);

if(value instanceof LocalDateTime) {
LocalDateTime localDateTime = (LocalDateTime) value;
if (value instanceof LocalDateTime localDateTime) {
return localDateTime.format(DateTimeFormatter.ofPattern(format));
} else if(value instanceof LocalDate) {
LocalDate localDate = (LocalDate) value;
} else if (value instanceof LocalDate localDate) {
return localDate.format(DateTimeFormatter.ofPattern(format));
} else {
log.warn("Value '{}' is not a date", value.toString());
log.warn("Value '{}' is not a date", value != null ? value.toString() : null);
}

return returnValue(propertyName, value);
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/com/avispa/ecm/util/parser/ParserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ public final class ParserFactory {
* @return
*/
public IFileParser get(String extension) {
switch (extension) {
case "txt":
return new TxtParser();
case "csv":
return new CsvParser(attributeSeparator);
default:
throw new IllegalArgumentException(String.format("Unsupported format: %s", extension));
}
return switch (extension) {
case "txt" -> new TxtParser();
case "csv" -> new CsvParser(attributeSeparator);
default -> throw new IllegalArgumentException(String.format("Unsupported format: %s", extension));
};
}
}
Loading

0 comments on commit e1e63d7

Please sign in to comment.