Skip to content

Commit

Permalink
Refactoring and bug fixing
Browse files Browse the repository at this point in the history
Increased tests coverage to over 80% and locked limit in Jacoco plugin
Sonar
  • Loading branch information
RHarryH committed Nov 20, 2023
1 parent 02bac2b commit a989b1a
Show file tree
Hide file tree
Showing 35 changed files with 1,606 additions and 411 deletions.
38 changes: 37 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<jodconverter.version>4.4.6</jodconverter.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<mapstruct.version>1.6.0.Beta1</mapstruct.version>
<sonar.skip>true</sonar.skip>
</properties>

<profiles>
<profile>
<id>sonar</id>

<properties>
<sonar.skip>false</sonar.skip>
</properties>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -169,6 +180,11 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.10.0.2594</version>
</plugin>
</plugins>
</pluginManagement>

Expand Down Expand Up @@ -232,6 +248,26 @@
</goals>
<phase>verify</phase>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.avispa.ecm.model.configuration.annotation;

import com.avispa.ecm.util.exception.EcmException;
import com.avispa.ecm.util.reflect.PropertyUtils;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -36,15 +37,19 @@ protected <A extends Annotation> A getFromAnnotation(Class<A> annotationClass, C

Field classMemberField = PropertyUtils.getField(actualClass, actualProperty);

if (null != classMemberField && classMemberField.isAnnotationPresent(annotationClass)) {
return classMemberField.getAnnotation(annotationClass);
}

if(log.isWarnEnabled()) {
log.warn("{} annotation not found for {} field", annotationClass.getSimpleName(), propertyName);
if (null != classMemberField) {
if(classMemberField.isAnnotationPresent(annotationClass)){
return classMemberField.getAnnotation(annotationClass);
} else {
if (log.isWarnEnabled()) {
log.warn("{} annotation not found for {} field", annotationClass.getSimpleName(), propertyName);
}
return null;
}
} else {
log.error("There is no field {} in {} class", propertyName, objectClass);
throw new EcmException("Can't determine display name for non existing '" + propertyName + "' property");
}

return null;
}

/**
Expand All @@ -61,7 +66,8 @@ private Class<?> getActualClass(Class<?> objectClass, String[] individualPropert
Field field = PropertyUtils.getField(actualClass, individual);

if(null == field) {
log.error("Error");
log.error("There is no field {} in {} class", individual, actualClass);
throw new EcmException("Can't determine display name for non existing '" + individual + "' property");
} else {
actualClass = field.getType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
* @author Rafał Hiszpański
Expand All @@ -41,6 +40,9 @@
@Entity
@Slf4j
public class Dictionary extends EcmConfig {
private static final String UNKNOWN_COLUMN = "UNKNOWN COLUMN";
private static final String UNKNOWN_KEY = "UNKNOWN KEY";

private String description;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "dictionary")
Expand All @@ -57,7 +59,7 @@ public String getLabel(String key) {
.filter(dictionaryValue -> dictionaryValue.getKey().equals(key))
.map(DictionaryValue::getLabel)
.findFirst()
.orElse("UNKNOWN KEY");
.orElse(UNKNOWN_KEY);
}

public String getColumnValue(String key, String columnName) {
Expand All @@ -67,21 +69,9 @@ public String getColumnValue(String key, String columnName) {

return values.stream()
.filter(dictionaryValue -> dictionaryValue.getKey().equals(key))
.map(dictionaryValue -> dictionaryValue.getColumns().get(columnName))
.findFirst()
.orElse("UNKNOWN COLUMN");
}

public String getColumnValue(UUID valueId, String columnName) {
if (isEmpty()) {
return null;
}

return values.stream()
.filter(dictionaryValue -> dictionaryValue.getId().equals(valueId))
.map(dictionaryValue -> dictionaryValue.getColumns().get(columnName))
.map(dictionaryValue -> dictionaryValue.getColumns().getOrDefault(columnName, UNKNOWN_COLUMN))
.findFirst()
.orElse("UNKNOWN COLUMN");
.orElse(UNKNOWN_COLUMN);
}

public DictionaryValue getValue(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.avispa.ecm.model.configuration.callable.autolink.Autolink;
import com.avispa.ecm.model.configuration.load.dto.AutolinkDto;
import com.avispa.ecm.util.Generated;
import org.mapstruct.AnnotateWith;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
Expand All @@ -29,6 +31,7 @@
/**
* @author Rafał Hiszpański
*/
@AnnotateWith(Generated.class)
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface AutolinkMapper extends EcmConfigMapper<Autolink, AutolinkDto> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.avispa.ecm.model.configuration.callable.autoname.Autoname;
import com.avispa.ecm.model.configuration.load.dto.AutonameDto;
import com.avispa.ecm.util.Generated;
import org.mapstruct.AnnotateWith;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
Expand All @@ -29,6 +31,7 @@
/**
* @author Rafał Hiszpański
*/
@AnnotateWith(Generated.class)
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface AutonameMapper extends EcmConfigMapper<Autoname, AutonameDto> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public abstract class ContextMapper implements EcmConfigMapper<Context, ContextD
@Autowired
private TypeService typeService;

@IterableMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
protected abstract List<EcmConfig> configNameToConfigObject(List<String> configNames);

@Override
@Mapping(source = "name", target = "objectName")
@Mapping(source = "configNames", target = "ecmConfigs")
@Mapping(target = "matchRule", defaultValue = "{}")
public abstract Context convertToEntity(ContextDto dto);

@IterableMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
protected abstract List<EcmConfig> configNameToConfigObject(List<String> configNames);

protected EcmConfig configNameToConfigObject(String configName) {
return ecmConfigRepository.findByObjectName(configName).orElseThrow(RepositoryCorruptionError::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.avispa.ecm.model.configuration.dictionary.DictionaryValue;
import com.avispa.ecm.model.configuration.load.dto.DictionaryValueDto;
import com.avispa.ecm.util.Generated;
import org.mapstruct.AnnotateWith;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
Expand All @@ -29,6 +31,7 @@
/**
* @author Rafał Hiszpański
*/
@AnnotateWith(Generated.class)
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface DictionaryValueMapper extends EcmConfigMapper<DictionaryValue, DictionaryValueDto> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.avispa.ecm.model.configuration.load.dto.PropertyPageDto;
import com.avispa.ecm.model.configuration.propertypage.PropertyPage;
import com.avispa.ecm.util.Generated;
import org.mapstruct.AnnotateWith;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
Expand All @@ -29,6 +31,7 @@
/**
* @author Rafał Hiszpański
*/
@AnnotateWith(Generated.class)
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface PropertyPageMapper extends EcmConfigMapper<PropertyPage, PropertyPageDto> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.avispa.ecm.model.configuration.load.dto.TemplateDto;
import com.avispa.ecm.model.configuration.template.Template;
import com.avispa.ecm.util.Generated;
import org.mapstruct.AnnotateWith;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
Expand All @@ -29,6 +31,7 @@
/**
* @author Rafał Hiszpański
*/
@AnnotateWith(Generated.class)
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface TemplateMapper extends EcmConfigMapper<Template, TemplateDto> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package com.avispa.ecm.model.configuration.propertypage.content.control;

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

Expand All @@ -31,8 +30,6 @@
@Setter
public class Table extends PropertyControl {
private List<PropertyControl> controls;
@JsonIgnore
private Class<?> propertyType; // TODO: required?

private int size;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Avispa ECM - a small framework for implementing basic ECM solution
* Copyright (C) 2023 Rafał Hiszpański
*
* 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 <https://www.gnu.org/licenses/>.
*/

package com.avispa.ecm.model.configuration.propertypage.content.mapper;

import com.avispa.ecm.model.configuration.propertypage.content.control.Control;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
* @author Rafał Hiszpański
*/
@Slf4j
@RequiredArgsConstructor
abstract class BaseControlsMapper<C extends Control> implements ControlMapper<C> {
protected static final String OBJECT_NAME = "objectName";

protected final DictionaryControlLoader dictionaryControlLoader;
protected final ObjectMapper objectMapper;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Avispa ECM - a small framework for implementing basic ECM solution
* Copyright (C) 2023 Rafał Hiszpański
*
* 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 <https://www.gnu.org/licenses/>.
*/

package com.avispa.ecm.model.configuration.propertypage.content.mapper;

import com.avispa.ecm.model.configuration.propertypage.content.control.Control;

/**
* @author Rafał Hiszpański
*/
interface ControlMapper<C extends Control> {
void processControl(C control, Object context);
}
Loading

0 comments on commit a989b1a

Please sign in to comment.