Skip to content

Commit

Permalink
replaced System.out.print calls with proper Logger info calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Navarro Piris committed Sep 4, 2017
1 parent 5a5dd53 commit 94653c2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,32 @@
import de.uni_stuttgart.vis.vowl.owl2vowl.model.ontology.OntologyMetric;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.owlapi.EntityCreationVisitor;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.owlapi.IndividualsVisitor;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.*;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.AnnotationParser;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.BaseIriCollector;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.EquivalentSorter;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.ImportedChecker;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.OntologyInformationParser;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.TypeSetter;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.classes.GenericClassAxiomVisitor;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.classes.HasKeyAxiomParser;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.classes.OwlClassAxiomVisitor;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.property.DataPropertyVisitor;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.property.DomainRangeFiller;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.property.ObjectPropertyVisitor;
import de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.property.VowlSubclassPropertyGenerator;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAxiom;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyAxiom;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.parameters.Imports;
import org.semanticweb.owlapi.search.EntitySearcher;
import org.semanticweb.owlapi.util.OWLOntologyWalker;
Expand All @@ -29,7 +44,9 @@
* The sub classes can specify the source of the ontology or to some additional processing if necessary.
*/
public abstract class AbstractConverter implements Converter {

private static final Logger logger = LogManager.getLogger(AbstractConverter.class);

protected final JsonGenerator jsonGenerator = new JsonGenerator();
protected String loadedOntologyPath;
protected OWLOntologyManager manager;
Expand All @@ -50,17 +67,16 @@ private void preLoadOntology() {
protected abstract void loadOntology() throws OWLOntologyCreationException;

private void preParsing(OWLOntology ontology, VowlData vowlData, OWLOntologyManager manager) {

OWLOntologyWalker walker = new OWLOntologyWalker(ontology.getImportsClosure());
EntityCreationVisitor ecv = new EntityCreationVisitor(vowlData);
walker.walkStructure(ecv);

try {
walker.walkStructure(ecv);
System.out.println("WalkStructure Success!");
logger.info("WalkStructure Success!");
} catch (Exception e) {
System.out.println("@WORKAROUND WalkSturcture Failed!");
System.out.println("Exception: " + e);
// System.out.println("Exit without export result, Sorry!");
// System.exit(-1);
logger.info("@WORKAROUND WalkStructure Failed!");
logger.info("Exception: " + e);
}
new OntologyInformationParser(vowlData, ontology).execute();
}
Expand All @@ -82,10 +98,10 @@ private void processIndividuals(OWLOntology ontology, VowlData vowlData, OWLOnto
owlIndividual, owlClass, manager)));
}
catch (Exception e){
System.out.println("@WORKAROUND: Failed to accept some individuals ... SKIPPING THIS" );
System.out.println("Exception: "+e);
System.out.println("----------- Continue Process --------");
continue;
logger.info("@WORKAROUND: Failed to accept some individuals ... SKIPPING THIS" );
logger.info("Exception: "+e);
logger.info("----------- Continue Process --------");
continue; // FIXME unnecessary continue, can be removed
}

}
Expand All @@ -98,10 +114,10 @@ private void processObjectProperties(OWLOntology ontology, VowlData vowlData) {
try {
owlObjectPropertyAxiom.accept(new ObjectPropertyVisitor(vowlData, owlObjectProperty));
} catch (Exception e){
System.out.println(" @WORKAROUND: Failed to accept property with HAS_VALUE OR SubObjectPropertyOf ... SKIPPING THIS" );
System.out.println(" propertyName: "+owlObjectProperty);
System.out.println(" propertyAxiom: "+owlObjectPropertyAxiom);
continue;
logger.info(" @WORKAROUND: Failed to accept property with HAS_VALUE OR SubObjectPropertyOf ... SKIPPING THIS" );
logger.info(" propertyName: "+owlObjectProperty);
logger.info(" propertyAxiom: "+owlObjectPropertyAxiom);
continue; // FIXME unnecessary continue, can be removed
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import de.uni_stuttgart.vis.vowl.owl2vowl.model.ontology.OntologyInformation;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.ontology.OntologyMetric;
import de.uni_stuttgart.vis.vowl.owl2vowl.util.ProjectInformations;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.semanticweb.owlapi.model.IRI;
Expand All @@ -23,6 +26,9 @@
*
*/
public class JsonGenerator {

private static final Logger logger = LogManager.getLogger(JsonGenerator.class);

private final String VERSION_INFORMATION = "Created with OWL2VOWL (version " + ProjectInformations.getVersion()
+ "), http://vowl.visualdataweb.org";
private Map<String, Object> root;
Expand Down Expand Up @@ -92,16 +98,16 @@ protected <V extends AbstractEntity> void convertEntities(Map<IRI, V> entityMap)
}
catch (Exception e){
IRI key =irivEntry.getKey();
System.out.println("WARNING! ");
System.out.println("*******************************");
System.out.println("Failed to Accept!");
System.out.println("Entity "+entity);
System.out.println("Key "+key);
System.out.println("Visitor "+visitor);
System.out.println("Reason : "+e);
logger.info("WARNING! ");
logger.info("*******************************");
logger.info("Failed to Accept!");
logger.info("Entity "+entity);
logger.info("Key "+key);
logger.info("Visitor "+visitor);
logger.info("Reason : "+e);
Class cls = entity.getClass();
System.out.println("The type of the object is: " + cls.getName());
System.out.println("*** SKIPPING THIS ***");
logger.info("The type of the object is: " + cls.getName());
logger.info("*** SKIPPING THIS ***");
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*
*/
public class ImportedChecker implements OWLNamedObjectVisitor {

// private static final Logger logger = LogManager.getLogger(ImportedChecker.class);

private final VowlData vowlData;
private final OWLOntologyManager manager;
private OWLOntology loadedOntology;
Expand All @@ -38,10 +41,10 @@ public void execute() {
// });

// Stream<OWLOntology> imports = manager.imports(loadedOntology);
// System.out.println("THE STREAM \n "+imports);
// logger.info("THE STREAM \n "+imports);
// List<String> strings = imports.map(Object::toString)
// .collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
// System.out.println("Strings \n "+strings);
// logger.info("Strings \n "+strings);

vowlData.getEntityMap().values().forEach(abstractEntity -> {
IRI entityIri = abstractEntity.getIri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlDatatypeProperty;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.properties.VowlObjectProperty;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.visitor.VowlPropertyVisitor;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.semanticweb.owlapi.model.IRI;

import java.util.Collection;
Expand All @@ -21,6 +24,8 @@
*/
public class DomainRangeFiller implements VowlPropertyVisitor {

private static final Logger logger = LogManager.getLogger(DomainRangeFiller.class);

private final VowlData vowlData;
private final Collection<? extends AbstractProperty> values;

Expand All @@ -43,10 +48,10 @@ private void fillEmpty() {
try {
element.accept(this);
} catch (Exception e){
System.out.println(" DomainRange Filler faild to accept element");
System.out.println(" Element: "+element);
System.out.println(" Reason: "+e);
System.out.println(" SKIPPING THIS ELEMENT *****");
logger.info(" DomainRange Filler faild to accept element");
logger.info(" Element: "+element);
logger.info(" Reason: "+e);
logger.info(" SKIPPING THIS ELEMENT *****");
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@
@RestController
public class Owl2VowlController {

private static final Logger logger = LogManager.getLogger(Owl2VowlController.class);

private static final Logger conversionLogger = LogManager.getLogger(LoggingConstants.CONVERSION_LOGGER);
private static final String СONVERT_MAPPING = "/convert";
private static final String READ_JSON = "/read";

@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Parameter not correct")
@ExceptionHandler(IllegalArgumentException.class)
public void parameterExceptionHandler(Exception e) {
System.out.println("--- Parameter exception: " + e.getMessage());
logger.info("--- Parameter exception: " + e.getMessage());
conversionLogger.error("Problems with parameters: " + e.getMessage());
}

@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Ontology could not be created")
@ExceptionHandler(OWLOntologyCreationException.class)
public void ontologyCreationExceptionHandler(Exception e) {
System.out.println("--- Ontology creation exception: " + e.getMessage());
logger.info("--- Ontology creation exception: " + e.getMessage());
conversionLogger.error("Problems in ontology creation process: " + e.getMessage());
}

@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Problems while generating uploaded file on server.")
@ExceptionHandler(IOException.class)
public void fileExceptionHandler(Exception e) {
System.out.println("--- IO exception: " + e.getMessage());
logger.info("--- IO exception: " + e.getMessage());
conversionLogger.error("IO exception while generating file on server: " + e.getMessage());
}

Expand Down Expand Up @@ -118,7 +120,7 @@ public String uploadJSON(@RequestParam("ontology") MultipartFile[] files) throws
jsonAsString=IOUtils.toString(inputStreams.get(0));
}
catch (Exception e){
System.out.println("Something went wrong");
logger.info("Something went wrong");
conversionLogger.error("Something went wrong " + e.getMessage());
}

Expand All @@ -137,7 +139,7 @@ public String readJsons(@RequestParam("json") String json) throws IOException, O
}
}
catch (Exception e){
System.out.println("Something went wrong");
logger.info("Something went wrong");
conversionLogger.error("Something went wrong " + e.getMessage());
}
return jsonAsString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@ public class ProjectInformations {
private static String version;

static {
Properties properties = new Properties();
InputStream inputStream = ProjectInformations.class.getResourceAsStream(VERSION_PROPERTIES_FILE);

try {
try (InputStream inputStream =
ProjectInformations.class.getResourceAsStream(VERSION_PROPERTIES_FILE)) {
Properties properties = new Properties();
properties.load(inputStream);
version = properties.getProperty("version", "");
} catch (IOException e) {
System.err.println(VERSION_PROPERTIES_FILE + " not found.");
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
// Do nothing
}
}

version = properties.getProperty("version", "");
}

public static String getVersion() {
Expand Down

0 comments on commit 94653c2

Please sign in to comment.