Commit 167982f7 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

logs in verifying annotations are structurized

parent b9d175da
......@@ -3,10 +3,13 @@ package lcsb.mapviewer.annotation.services;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.Marker;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
* Class describing improper annotation. All elements are annotated in the
......@@ -35,7 +38,7 @@ public class ImproperAnnotations implements ProblematicAnnotation {
* @param list
* list of improper {@link MiriamData}
* @param bioEntity
* bioentity
* bio entity
*/
public ImproperAnnotations(BioEntity bioEntity, List<MiriamData> list) {
if (list.size() == 0) {
......@@ -61,8 +64,7 @@ public class ImproperAnnotations implements ProblematicAnnotation {
@Override
public String getMessage() {
StringBuilder result = new StringBuilder(new ElementUtils().getElementTag(bioEntity));
result.append("contains invalid annotations: ");
StringBuilder result = new StringBuilder("Invalid annotations found: ");
for (MiriamData miriamData : wrongAnnotations) {
result.append(miriamData.getDataType().getCommonName() + "(" + miriamData.getResource() + "), ");
}
......@@ -74,4 +76,9 @@ public class ImproperAnnotations implements ProblematicAnnotation {
return getMessage();
}
@Override
public Marker getLogMarker() {
return new LogMarker(ProjectLogEntryType.INVALID_ANNOTATION, bioEntity);
}
}
package lcsb.mapviewer.annotation.services;
import org.apache.logging.log4j.Marker;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.modelutils.map.ElementUtils;
......@@ -29,7 +33,7 @@ public class MissingAnnotation implements ProblematicAnnotation {
@Override
public String getMessage() {
return new ElementUtils().getElementTag(bioEntity) + "misses annotations.";
return "Missing annotations.";
}
@Override
......@@ -37,4 +41,9 @@ public class MissingAnnotation implements ProblematicAnnotation {
return getMessage();
}
@Override
public Marker getLogMarker() {
return new LogMarker(ProjectLogEntryType.MISSING_ANNOTATION, bioEntity);
}
}
......@@ -2,7 +2,11 @@ package lcsb.mapviewer.annotation.services;
import java.util.*;
import org.apache.logging.log4j.Marker;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.modelutils.map.ElementUtils;
......@@ -44,8 +48,7 @@ public class MissingRequiredAnnotations implements ProblematicAnnotation {
@Override
public String getMessage() {
StringBuilder result = new StringBuilder(new ElementUtils().getElementTag(bioEntity));
result.append("misses one of the following annotations: ");
StringBuilder result = new StringBuilder("Missing one of the required annotations: ");
for (MiriamType type : requiredMiriamType) {
result.append(type.getCommonName() + ", ");
}
......@@ -57,4 +60,9 @@ public class MissingRequiredAnnotations implements ProblematicAnnotation {
return getMessage();
}
@Override
public Marker getLogMarker() {
return new LogMarker(ProjectLogEntryType.MISSING_REQUIRED_ANNOTATION, bioEntity);
}
}
......@@ -12,6 +12,7 @@ import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Reaction;
......@@ -244,7 +245,7 @@ public class ModelAnnotator {
public Collection<ImproperAnnotations> findImproperAnnotations(Model m, IProgressUpdater updater,
Map<Class<? extends BioEntity>, Set<MiriamType>> validAnnotations) {
if (validAnnotations == null) {
logger.warn("List of valid annotations is missing. Using default.");
logger.warn(LogMarker.IGNORE, "List of valid annotations is missing. Using default.");
validAnnotations = getDefaultValidClasses();
}
updater.setProgress(0.0);
......@@ -310,14 +311,14 @@ public class ModelAnnotator {
* model where the search is performed
* @param requestedAnnotations
* map that contains information which {@link MiriamType miriam types}
* are obigatory for which class
* are obligatory for which class
*
* @return list of all elements that miss annotation
*/
public Collection<ProblematicAnnotation> findMissingAnnotations(Model m,
Map<Class<? extends BioEntity>, Set<MiriamType>> requestedAnnotations) {
if (requestedAnnotations == null) {
logger.warn("List of requested annotations is missing. Using default.");
logger.warn(LogMarker.IGNORE, "List of requested annotations is missing. Using default.");
requestedAnnotations = getDefaultRequiredClasses();
}
List<ProblematicAnnotation> result = new ArrayList<>();
......
package lcsb.mapviewer.annotation.services;
import org.apache.logging.log4j.Marker;
/**
* Interface that describes annotation that is problematic.
*
......@@ -14,4 +16,6 @@ public interface ProblematicAnnotation {
* @return problem error message
*/
String getMessage();
Marker getLogMarker();
}
package lcsb.mapviewer.model;
import org.apache.logging.log4j.Marker;
import lcsb.mapviewer.common.exception.NotImplementedException;
public class IgnoredLogMarker implements Marker {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public Marker addParents(Marker... markers) {
throw new NotImplementedException();
}
@Override
public String getName() {
throw new NotImplementedException();
}
@Override
public Marker[] getParents() {
throw new NotImplementedException();
}
@Override
public boolean hasParents() {
throw new NotImplementedException();
}
@Override
public boolean isInstanceOf(Marker m) {
throw new NotImplementedException();
}
@Override
public boolean isInstanceOf(String name) {
throw new NotImplementedException();
}
@Override
public boolean remove(Marker marker) {
throw new NotImplementedException();
}
@Override
public Marker setParents(Marker... markers) {
throw new NotImplementedException();
}
}
......@@ -12,6 +12,8 @@ public class LogMarker implements Marker {
*/
private static final long serialVersionUID = 1L;
public static final Marker IGNORE = new IgnoredLogMarker();
private ProjectLogEntry entry;
public LogMarker(ProjectLogEntryType type, BioEntity bioEntity) {
......
package lcsb.mapviewer.model;
public enum ProjectLogEntryType {
OTHER,
ANNOTATION_CONFLICT,
CANNOT_FIND_INFORMATION,
DATABASE_PROBLEM,
INVALID_ANNOTATION,
INVALID_IDENTIFIER,
ANNOTATION_CONFLICT,
MISSING_ANNOTATION,
MISSING_REQUIRED_ANNOTATION,
OUT_OF_MEMORY,
DATABASE_PROBLEM
OTHER,
}
......@@ -983,20 +983,18 @@ public class ProjectService implements IProjectService {
updateProjectStatus(originalModel.getProject(), ProjectStatus.VALIDATING_MIRIAM, progress, params);
}
}, params.getValidAnnotations());
List<String> res = new ArrayList<>();
for (ProblematicAnnotation improperAnnotation : improperAnnotations) {
res.add(improperAnnotation.toString());
for (ProblematicAnnotation problematicAnnotation : improperAnnotations) {
logger.warn(problematicAnnotation.getLogMarker(), problematicAnnotation.getMessage());
}
Collections.sort(res);
Collection<? extends ProblematicAnnotation> missingAnnotations = modelAnnotator
.findMissingAnnotations(originalModel, params.getRequiredAnnotations());
for (ProblematicAnnotation improperAnnotation : missingAnnotations) {
res.add(improperAnnotation.toString());
}
for (String message : res) {
logger.warn(message);
for (ProblematicAnnotation problematicAnnotation : missingAnnotations) {
logger.warn(problematicAnnotation.getLogMarker(), problematicAnnotation.getMessage());
}
logger.debug("Analyze finished");
}
......@@ -1176,17 +1174,21 @@ public class ProjectService implements IProjectService {
for (LogEvent event : appender.getErrors()) {
result.add(createLogEntry("ERROR", event));
}
result.remove(null);
return result;
}
private ProjectLogEntry createLogEntry(String severity, LogEvent event) {
if (event.getMarker() instanceof IgnoredLogMarker) {
return null;
}
ProjectLogEntry entry = null;
if (event.getMarker() != null) {
if (event.getMarker() instanceof LogMarker) {
entry = ((LogMarker) event.getMarker()).getEntry();
}
}
if (entry==null) {
if (entry == null) {
entry = new ProjectLogEntry();
entry.setType(ProjectLogEntryType.OTHER);
}
......
......@@ -682,4 +682,17 @@ public class ProjectServiceTest extends ServiceTestFunctions {
assertEquals(3, entries.size());
}
@Test
public void testCreateIgnoredLogEntries() throws Exception {
MinervaLoggerAppender appender = MinervaLoggerAppender.createAppender();
appender.append(Log4jLogEvent.newBuilder()
.setLevel(Level.WARN)
.setMessage(new SimpleMessage("Hello world"))
.setMarker(LogMarker.IGNORE)
.build());
ProjectService service = Mockito.mock(ProjectService.class, Mockito.CALLS_REAL_METHODS);
Set<ProjectLogEntry> entries = service.createLogEntries(appender);
assertEquals(0, entries.size());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment