Commit d231b8bd authored by Piotr Gawron's avatar Piotr Gawron
Browse files

logger entries are translated to project log entries

parent a87bb1ae
package lcsb.mapviewer.model;
import org.apache.logging.log4j.Marker;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.BioEntity;
public class LogMarker implements Marker {
/**
*
*/
private static final long serialVersionUID = 1L;
private ProjectLogEntry entry;
public LogMarker(String type, BioEntity bioEntity) {
entry = new ProjectLogEntry();
entry.setType(type);
if (bioEntity != null) {
entry.setObjectIdentifier(bioEntity.getElementId());
entry.setObjectClass(bioEntity.getClass().getSimpleName());
if (bioEntity.getModel() != null) {
entry.setMapName(bioEntity.getModel().getName());
}
}
}
@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();
}
public ProjectLogEntry getEntry() {
return entry;
}
}
......@@ -815,6 +815,9 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument {
@XmlTransient
@Override
public Model getModel() {
if (model == null) {
return null;
}
return model.getModel();
}
......
......@@ -9,6 +9,7 @@ import javax.mail.MessagingException;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LogEvent;
import org.hibernate.HibernateException;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;
......@@ -22,7 +23,6 @@ import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.commands.*;
import lcsb.mapviewer.common.*;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.*;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.converter.graphics.MapGenerator;
......@@ -1167,8 +1167,31 @@ public class ProjectService implements IProjectService {
return project;
}
private Set<ProjectLogEntry> createLogEntries(MinervaLoggerAppender appender) {
throw new NotImplementedException();
Set<ProjectLogEntry> createLogEntries(MinervaLoggerAppender appender) {
Set<ProjectLogEntry> result = new HashSet<>();
for (LogEvent event : appender.getWarnings()) {
result.add(createLogEntry("WARNING", event));
}
for (LogEvent event : appender.getErrors()) {
result.add(createLogEntry("ERROR", event));
}
return result;
}
private ProjectLogEntry createLogEntry(String severity, LogEvent event) {
ProjectLogEntry entry = null;
if (event.getMarker() != null) {
if (event.getMarker() instanceof LogMarker) {
entry = ((LogMarker) event.getMarker()).getEntry();
}
}
if (entry==null) {
entry = new ProjectLogEntry();
entry.setType("OTHER");
}
entry.setSeverity(severity);
entry.setContent(event.getMessage().getFormattedMessage());
return entry;
}
}
......@@ -8,8 +8,9 @@ import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.poi.util.IOUtils;
import org.junit.*;
import org.mockito.Mockito;
......@@ -18,20 +19,19 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import lcsb.mapviewer.commands.CopyCommand;
import lcsb.mapviewer.common.MinervaLoggerAppender;
import lcsb.mapviewer.converter.ComplexZipConverter;
import lcsb.mapviewer.converter.ComplexZipConverterParams;
import lcsb.mapviewer.converter.graphics.MapGenerator;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.converter.zip.*;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectStatus;
import lcsb.mapviewer.model.*;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.DataOverlayImageLayer;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.user.*;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.map.LayoutDao;
......@@ -657,4 +657,29 @@ public class ProjectServiceTest extends ServiceTestFunctions {
assertEquals(ProjectStatus.FAIL, project.getStatus());
projectService.removeProject(project, null, false);
}
@Test
public void testCreateLogEntries() throws Exception {
Protein protein = new GenericProtein("id");
MinervaLoggerAppender appender = MinervaLoggerAppender.createAppender();
appender.append(Log4jLogEvent.newBuilder()
.setLevel(Level.WARN)
.setMessage(new SimpleMessage("Hello world"))
.setMarker(new LogMarker("type", protein))
.build());
appender.append(Log4jLogEvent.newBuilder()
.setLevel(Level.ERROR)
.setMessage(new SimpleMessage("Hello world 2"))
.setMarker(new LogMarker("type2", protein))
.build());
appender.append(Log4jLogEvent.newBuilder()
.setLevel(Level.ERROR)
.setMessage(new SimpleMessage("Hello world 3"))
.build());
ProjectService service = Mockito.mock(ProjectService.class, Mockito.CALLS_REAL_METHODS);
Set<ProjectLogEntry> entries = service.createLogEntries(appender);
assertEquals(3, entries.size());
}
}
Supports Markdown
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