public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -0,0 +1,7 @@
<?flintstones.helper.data.xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.helper.data.io</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] flintstones.helper.data.io</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.helper.data.io</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1779484362606</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,33 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: flintstones.helper.data.io
Bundle-SymbolicName: flintstones.helper.data.io;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.helper.data.io
Bundle-RequiredExecutionEnvironment: JavaSE-11
Export-Package: flintstones.helper.data.io
Require-Bundle: flintstones.application.constants,
javanet.staxutils,
flintstones.entity.problemelement,
flintstones.entity.valuation,
flintstones.model.valuation.service,
flintstones.helper.data.wxml,
flintstones.model.ahppreferences.service,
javax.inject,
flintstones.entity.ahppreferences,
flintstones.model.problemelement.service,
org.eclipse.e4.core.services,
flintstones.model.ahpsort.profileassignment.service,
flintstones.entity.ahpsort.profileassignment,
flintstones.entity.preferences.preferencecollection,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.di,
flintstones.model.domain.service,
javax.annotation,
flintstones.model.method.service,
flintstones.helper.data,
flintstones.model.ahp.referencepoint.service,
flintstones.entity.ahpsort.referencepoint,
flintstones.helper.debug,
flintstones.model.application.service,
flintstones.helper.extensionpoint
@@ -0,0 +1,6 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
schema/
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="flintstones.helper.data.io" name="Import/Export FS" schema="schema/flintstones.helper.data.io.exsd"/>
<extension
point="flintstones.helper.data.io">
<import_module
implementation="flintstones.helper.data.io.modules.IOProblemElements30"
version_mayor="3"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IODomain30"
version_mayor="3"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IODomainValuation30"
version_mayor="3"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IODomainAssignments30"
version_mayor="3"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IOValuation30"
version_mayor="3"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IOApplication40"
version_mayor="4"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IOProblemElements40"
version_mayor="4"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IODomain40"
version_mayor="4"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IODomainAssignments40"
version_mayor="4"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IOValuation40"
version_mayor="4"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IOProfileAssignment40"
version_mayor="4"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IOReferencePoints40"
version_mayor="4"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IOPreferences40"
version_mayor="4"
version_minor="0">
</import_module>
<import_module
implementation="flintstones.helper.data.io.modules.IOSortingClass40"
version_mayor="4"
version_minor="0">
</import_module>
</extension>
</plugin>
@@ -0,0 +1,123 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="flintstones.helper.data.io" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="flintstones.helper.data.io" id="flintstones.helper.data.io" name="Import/Export FS"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="import_module"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="import_module">
<complexType>
<attribute name="implementation" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn="flintstones.helper.data.io.interfaces.BaseIO:"/>
</appinfo>
</annotation>
</attribute>
<attribute name="version_mayor" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="version_minor" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="version_patch" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
@@ -0,0 +1,83 @@
package flintstones.helper.data.io;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.application.constants.FrameworkConstants;
import flintstones.model.ahp.referencepoint.service.IReferencePointService;
import flintstones.model.ahppreferences.service.IProblemPreferencesService;
import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.method.service.IMethodService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
/**
* The Class ClearData.
*/
public class ClearData {
/** The valuation service. */
@Inject
IValuationService valuationService;
/** The domain service. */
@Inject
IDomainService domainService;
/** The problem service. */
@Inject
IProblemElementService problemService;
@Inject
IMethodService methodService;
@Inject
IProblemPreferencesService prefService;
@Inject
IProfileAssignmentService profileAssignmentService;
@Inject
IReferencePointService referencePointService;
/** The broker. */
@Inject
IEventBroker broker;
@PostConstruct
private void init() {
}
/**
* Execute the handler.
*/
public void execute() {
this.clear();
this.sendEvents();
}
/**
* Clear the data in the model.
*/
private void clear() {
this.problemService.deleteAll();
this.domainService.clear();
this.valuationService.clear();
this.methodService.clear();
this.prefService.clear();
this.profileAssignmentService.clear();
this.referencePointService.clear();
}
/**
* Send events to refresh the UI.
*/
private void sendEvents() {
this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, FrameworkConstants.empty());
this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_DELETED, null);
this.broker.post(FrameworkConstants.TOPIC_VALUATION_CREATED, null);
}
}
@@ -0,0 +1,187 @@
package flintstones.helper.data.io;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import flintstones.application.constants.FrameworkConstants;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
import flintstones.helper.data.wxml.exception.WNodeNotFound;
import flintstones.helper.debug.DH;
import flintstones.helper.extensionpoint.BaseRegistry;
import flintstones.helper.extensionpoint.ExtensionRegistry;
import javanet.staxutils.IndentingXMLStreamWriter;
/**
* The Class FlintstonesIO.
*/
@SuppressWarnings("nls")
public class FlintstonesIO {
/** The broker. */
@Inject
IEventBroker broker;
/** The context. */
@Inject
IEclipseContext context;
/**
* Load a file.
*
* @param fileName the file name
*/
public void load(String fileName) {
try {
this.loadFile(fileName);
this.sendEvents();
} catch (ParserConfigurationException | IOException | SAXException e1) {
DH.out("No se ha podido cargar el fichero " + fileName);
e1.printStackTrace();
}
}
/**
* Load file.
*
* @param fileName the file name
* @throws ParserConfigurationException the parser configuration exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws SAXException the SAX exception
*/
private void loadFile(String fileName) throws ParserConfigurationException, IOException, SAXException {
DH.l();
DH.out("I/O","!INFOFS Cargando el fichero " + fileName);
Element node = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(new File(fileName))
.getDocumentElement();
WNode wnode = new WNode(node);
WNode nodex = wnode.getFirst("resolution.phase");
String version = nodex.getAttribute("version") != null ? nodex.getAttribute("version") : "3.0";
wnode.setVersion(version);
this.load(wnode);
}
/**
* Load.
*
* @param node the nod
* @param version the version
*/
private void load(WNode node) {
DH.out("I/O","!INFOFS Leyendo la versión " + node.getVersion());
List<BaseIO> importModules = getIOModules();
for (BaseIO io : importModules) {
if (!io.getVersion().equals(node.getVersion())) {
continue;
}
io.beforeRead();
WNode ioNode = null;
try {
ioNode = node.getFirst("id", io.getPhase());
WNode ioNode2 = ioNode.getFirst(io.getPart());
io.read(ioNode2);
io.afterRead();
} catch (WNodeNotFound e) {
System.out.println(e.getMessage());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private List<BaseIO> getIOModules() {
List<BaseIO> importModules = new ArrayList<BaseIO>();
BaseRegistry basereg = new BaseRegistry("flintstones.helper.data.io");
ExtensionRegistry[] regs = basereg.getAllRegistries();
for(ExtensionRegistry reg : regs) {
BaseIO importModule = (BaseIO) basereg.instantiate(reg, context);
importModule.setVersion(reg.getAttribute("version_mayor"), reg.getAttribute("version_minor"));
importModules.add(importModule);
}
return importModules;
}
/**
* Write file.
*
* @param fileName the file name
* @throws ParserConfigurationException the parser configuration exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws SAXException the SAX exception
* @throws XMLStreamException the XML stream exception
*/
public void writeFile(String fileName) throws IOException, XMLStreamException {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = new IndentingXMLStreamWriter(factory.createXMLStreamWriter(new FileOutputStream(fileName), "UTF-8"));
List<BaseIO> importModules = getIOModules();
DH.l();
DH.out("!INFOFS Guardando en el fichero " + fileName);
writer.writeStartDocument();
writer.writeStartElement("resolution.scheme");
for (BaseIO io : importModules) {
if (!io.getVersion()
.equals("4.0"))
continue;
writer.writeStartElement("resolution.phase");
writer.writeAttribute("id", io.getPhase());
writer.writeAttribute("version", "4.0");
writer.writeStartElement(io.getPart());
io.beforeWrite();
io.setWriter(writer);
io.write();
io.afterWrite();
writer.writeEndElement();
writer.writeEndElement();
}
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
}
/**
* Send events.
*/
private void sendEvents() {
this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, FrameworkConstants.empty() );
this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_CREATED, null);
this.broker.post(FrameworkConstants.TOPIC_VALUATION_CREATED, null);
this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_SORTINGPROFILE_CREATED, null);
}
}
@@ -0,0 +1,116 @@
package flintstones.helper.data.io.interfaces;
import java.text.MessageFormat;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import flintstones.helper.data.wxml.WNode;
import flintstones.helper.debug.DH;
/**
* The Class BaseIO.
*/
public abstract class BaseIO {
/** The expected number of loadedItems. */
protected int expected = 0;
/** The valid number of loadedItems. */
protected int valid = 0;
/** The failed number of loadedItems. */
protected int failed = 0;
/** The writer. */
protected XMLStreamWriter writer;
/** The version id. */
protected String version = "X.X"; //$NON-NLS-1$
/**
* Before write do this.
*/
public void beforeWrite() {
};
/**
* Before read do this.
*/
public abstract void beforeRead();
/**
* Read the XML node.
*
* @param node the node
*/
public abstract void read(WNode node);
/**
* Write.
*
* @throws XMLStreamException the XML stream exception
*/
public abstract void write() throws XMLStreamException;
/**
* Sets the writer.
*
* @param writer the new writer
* @throws XMLStreamException the XML stream exception
*/
public void setWriter(XMLStreamWriter writer) throws XMLStreamException {
this.writer = writer;
};
/**
* Gets the phase.
*
* @return the phase
*/
public abstract String getPhase();
/**
* Gets the part.
*
* @return the part
*/
public abstract String getPart();
public void afterRead() {
String msg = ""; //$NON-NLS-1$
if (this.expected > 0)
msg = "!INFOFS Cargados {0}/{1} en {3}"; //$NON-NLS-1$
else
msg = "!INFOFS Cargados {0} en {3}"; //$NON-NLS-1$
if (this.failed == 1)
msg += " con un fallo"; //$NON-NLS-1$
else if (this.failed > 1)
msg += ", con {2} fallos"; //$NON-NLS-1$
String loader = this.getClass()
.asSubclass(this.getClass())
.getSimpleName();
String msg2 = MessageFormat.format(msg, this.valid, this.expected, this.failed, loader);
DH.out("I/O",msg2);
}
public void afterWrite() {
};
/**
* Gets the version.
*
* @return the version
*/
public String getVersion() {
return this.version;
}
public void setVersion(String mayor, String minor) {
this.version = mayor + "." + minor;
}
}
@@ -0,0 +1,18 @@
package flintstones.helper.data.io.interfaces;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
public abstract class BaseIO30 extends BaseIO {
@Override
public void setWriter(XMLStreamWriter writer) {
}
@Override
public void write() throws XMLStreamException {
}
}
@@ -0,0 +1,53 @@
package flintstones.helper.data.io.modules;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import flintstones.application.model.IApplicationService;
import flintstones.application.model.ProblemType;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
public class IOApplication40 extends BaseIO {
@Inject
IApplicationService appService;
public IOApplication40() {
}
@Override
public void beforeRead() {
}
@Override
public void read(WNode node) {
WNode wnode = node.getFirst("data");
String problemType = wnode.getAttribute("problemType");
if (problemType != null) {
if (problemType.equals(ProblemType.Ranking.toString()))
appService.launchProblem(ProblemType.Ranking);
else if (problemType.equals(ProblemType.Sorting.toString()))
appService.launchProblem(ProblemType.Sorting);
}
}
@Override
public void write() throws XMLStreamException {
writer.writeStartElement("data");
writer.writeAttribute("problemType", appService.getProblemType().toString());
writer.writeEndElement();
}
@Override
public String getPhase() {
return "flintstones.application";
}
@Override
public String getPart() {
return "application";
}
}
@@ -0,0 +1,80 @@
package flintstones.helper.data.io.modules;
import java.util.List;
import javax.inject.Inject;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.domain.Domain;
import flintstones.helper.data.io.interfaces.BaseIO30;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.domain.service.IDomainService;
/**
* The Class IODomain30.
*/
public class IODomain30 extends BaseIO30 {
/** The domain service. */
@Inject
IDomainService domainService;
/** The broker. */
@Inject
IEventBroker broker;
/**
* Instantiates a new IO domain 30.
*/
public IODomain30() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
List<WNode> nodes = node.getChildren();
this.expected = nodes.size();
for (WNode item : nodes) {
String extensionPointId = item.getName();
String domainName = item.getAttribute("id"); //$NON-NLS-1$
Domain domain = this.domainService.create(extensionPointId);
domain.read(item);
domain.setName(domainName);
this.domainService.add(domain);
this.valid++;
}
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.framework"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "domain-set"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
this.domainService.clear();
}
}
@@ -0,0 +1,105 @@
package flintstones.helper.data.io.modules;
import java.util.List;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.domain.Domain;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.domain.service.IDomainService;
/**
* The Class IODomain40.
*/
public class IODomain40 extends BaseIO {
/** The domain service. */
@Inject
IDomainService domainService;
/** The broker. */
@Inject
IEventBroker broker;
/**
* Instantiates a new IO domain 40.
*/
public IODomain40() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
List<WNode> nodes = node.getChildren();
this.expected = nodes.size();
for (WNode item : nodes) {
String extensionPointId = item.getAttribute(Domain.Fields.type);
String itemName = item.getAttribute(Domain.Fields.name);
Domain domain = this.domainService.create(extensionPointId);
domain.read(item);
domain.setName(itemName);
this.domainService.add(domain);
this.valid++;
}
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#write() */
@Override
public void write() throws XMLStreamException {
Domain[] arr = this.domainService.getAll();
for (Domain d : arr)
this.writeDomain(d);
}
/**
* Write domain.
*
* @param d the d
* @throws XMLStreamException the XML stream exception
*/
private void writeDomain(Domain d) throws XMLStreamException {
this.writer.writeStartElement(Domain.class.getSimpleName().toLowerCase());
this.writer.writeAttribute(Domain.Fields.type.toString(), d.getType());
this.writer.writeAttribute(Domain.Fields.name.toString(), d.getName());
d.write(this.writer);
this.writer.writeEndElement();
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.framework.domains"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "domains"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
this.domainService.clear();
}
}
@@ -0,0 +1,110 @@
package flintstones.helper.data.io.modules;
import java.util.List;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamWriter;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.domain.Domain;
import flintstones.entity.problemelement.ProblemElementKey;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.io.interfaces.BaseIO30;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
/**
* The Class IODomainAssignments30.
*/
public class IODomainAssignments30 extends BaseIO30 {
/** The valuation service. */
@Inject
IValuationService valuationService;
/** The problem service. */
@Inject
IProblemElementService problemService;
/** The domain service. */
@Inject
IDomainService domainService;
/** The broker. */
@Inject
IEventBroker broker;
/**
* Instantiates a new IO domain assignments 30.
*/
public IODomainAssignments30() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
List<WNode> nodes = node.getChildren();
this.expected = nodes.size();
for (WNode item : nodes) {
String domainName = item.getAttribute("domain"); //$NON-NLS-1$
String expertCanonicalName = item.getAttribute("expert"); //$NON-NLS-1$
String alternativeCanonicalName = item.getAttribute("alternative"); //$NON-NLS-1$
String criterionCanonicalName = item.getAttribute("criterion"); //$NON-NLS-1$
Domain domain = this.domainService.getByName(domainName);
Expert expert = (Expert) this.problemService.getByCanonicalName(Expert.Type, expertCanonicalName);
Alternative alternative = (Alternative) this.problemService.getByCanonicalName(Alternative.Type, alternativeCanonicalName);
Criterion criterion = (Criterion) this.problemService.getByCanonicalName(Criterion.Type, criterionCanonicalName);
ProblemElementKey pek = new ProblemElementKey(expert, alternative, criterion);
Valuation v = this.valuationService.create(domain);
this.valuationService.addOrUpdate(pek, v);
this.valid++;
}
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
// valuationService.clear();
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.frameworkstructuring"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "domain-assignments"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see
* flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */
@Override
public void setWriter(XMLStreamWriter writer) {
}
}
@@ -0,0 +1,144 @@
package flintstones.helper.data.io.modules;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.domain.Domain;
import flintstones.entity.problemelement.ProblemElementKey;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
/**
* The Class IODomainAssignments40.
*/
public class IODomainAssignments40 extends BaseIO {
/** The valuation service. */
@Inject
IValuationService valuationService;
/** The problem service. */
@Inject
IProblemElementService problemService;
/** The domain service. */
@Inject
IDomainService domainService;
/** The broker. */
@Inject
IEventBroker broker;
/**
* Instantiates a new IO domain assignments 40.
*/
public IODomainAssignments40() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
List<WNode> nodes = node.getChildren();
this.expected = nodes.size();
for (WNode item : nodes) {
String domainName = item.getAttribute(Domain.Fields.Domain);
String expertCanonicalName = item.getAttribute(Expert.Fields.Expert);
String alternativeCanonicalName = item.getAttribute(Alternative.Fields.Alternative);
String criterionCanonicalName = item.getAttribute(Criterion.Fields.Criterion);
Domain domain = this.domainService.getByName(domainName);
Expert expert = (Expert) this.problemService.getByName(Expert.Fields.Expert.toString(), expertCanonicalName);
Alternative alternative = (Alternative) this.problemService.getByName(Alternative.Fields.Alternative.toString(), alternativeCanonicalName);
Criterion criterion = (Criterion) this.problemService.getByName(Criterion.Fields.Criterion.toString(), criterionCanonicalName);
ProblemElementKey pek = new ProblemElementKey(expert, alternative, criterion);
Valuation v = this.valuationService.create(domain);
this.valuationService.addOrUpdate(pek, v);
this.valid++;
}
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#write() */
@Override
public void write() throws XMLStreamException {
LinkedHashMap<ProblemElementKey, Valuation> valuations = this.valuationService.getAllKV();
for (Entry<ProblemElementKey, Valuation> entry : valuations.entrySet())
this.writeAssignment(entry.getKey()
.getExpert(),
entry.getKey()
.getAlternative(),
entry.getKey()
.getCriterion(),
entry.getValue()
.getDomain(),
entry.getValue());
}
/**
* Write assignment.
*
* @param e the expert
* @param a the alternative
* @param c the criterion
* @param d the domain
* @throws XMLStreamException the XML stream exception
*/
private void writeAssignment(Expert e, Alternative a, Criterion c, Domain d, Valuation v) throws XMLStreamException {
this.writer.writeStartElement("assignment"); //$NON-NLS-1$
this.writer.writeAttribute(Expert.Fields.Expert.toString(), e.getName());
this.writer.writeAttribute(Alternative.Fields.Alternative.toString(), a.getName());
this.writer.writeAttribute(Criterion.Fields.Criterion.toString(), c.getName());
this.writer.writeAttribute(Domain.Fields.Domain.toString(), d.getName());
this.writer.writeAttribute(Valuation.Fields.Valuation.toString(), v.getId());
this.writer.writeEndElement();
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
// valuationService.clear();
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.frameworkstructuring"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "domain-assignments"; //$NON-NLS-1$
}
}
@@ -0,0 +1,120 @@
package flintstones.helper.data.io.modules;
import java.util.List;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamWriter;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.domain.Domain;
import flintstones.helper.data.io.interfaces.BaseIO30;
import flintstones.helper.data.wxml.WNode;
import flintstones.helper.debug.DH;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
/**
* The Class IODomainValuation30.
*/
public class IODomainValuation30 extends BaseIO30 {
/** The valuation service. */
@Inject
IValuationService valuationService;
/** The problem service. */
@Inject
IProblemElementService problemService;
/** The domain service. */
@Inject
IDomainService domainService;
/** The broker. */
@Inject
IEventBroker broker;
/**
* Instantiates a new IO domain valuation 30.
*/
public IODomainValuation30() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
List<WNode> nodes = node.getChildren();
this.expected = nodes.size() / 2;
for (int i = 0; i < nodes.size(); i += 2) {
WNode domainItem = nodes.get(i);
WNode valuationItem = nodes.get(i + 1);
String domainName = domainItem.getAttribute("id"); //$NON-NLS-1$
String valuationId = valuationItem.getAttribute("id"); //$NON-NLS-1$
this.fixDomainType(domainName, valuationId);
}
}
/**
* Fix domain type. The old flintstone won't save different domain type for some hesitant/fuzzy domains.
* This methods fix it.
* @param domainName the domain name
* @param valuationId the valuation id
*/
private void fixDomainType(String domainName, String valuationId) {
String newType = this.valuationService.getDomainFor(valuationId);
Domain domain = this.domainService.getByName(domainName);
// En FS3, si borras un dominio con valuation, el dominio se borra pero el par
// dominio-valuatio no.
if (domain != null) {
domain.setType(newType);
this.valid++;
} else {
DH.out("!ERRORFS Fallo al asignar el dominio " + domainName); //$NON-NLS-1$
this.failed++;
}
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
this.valuationService.clear();
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.framework"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "domain-valuation"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see
* flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */
@Override
public void setWriter(XMLStreamWriter writer) {
}
}
@@ -0,0 +1,267 @@
package flintstones.helper.data.io.modules;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.ahppreferences.PreferenceBuild;
import flintstones.entity.ahppreferences.PreferenceCollectionKey;
import flintstones.entity.ahppreferences.PreferenceMatrix;
import flintstones.entity.preferences.preferencecollection.PreferenceCollection;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.ahppreferences.service.IProblemPreferencesService;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
/**
* The Class IOValuation40.
*/
public class IOPreferences40 extends BaseIO {
/** The valuation service. */
@Inject
IValuationService valuationService;
/** The problem service. */
@Inject
IProblemElementService problemService;
/** The domain service. */
@Inject
IDomainService domainService;
/** The broker. */
@Inject
IEventBroker broker;
@Inject
IProblemPreferencesService preferencesService;
/**
* Instantiates a new IO valuation 40.
*/
public IOPreferences40() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
if(node == null)
return ;
List<WNode> preferenceCollections = node.getFirst(PreferenceCollection.Fields.PreferenceCollections).getChildren();
for(WNode preferenceNode : preferenceCollections ) {
String mainType = preferenceNode.getAttribute(PreferenceCollection.Fields.mainType);
String otherType = preferenceNode.getAttribute(PreferenceCollection.Fields.otherType);
String leftType = preferenceNode.getAttribute(PreferenceCollection.Fields.leftType);
String rightType = preferenceNode.getAttribute(PreferenceCollection.Fields.rightType);
ArrayList<PreferenceBuild> builds = new ArrayList<>();
List<WNode> buildNodes = preferenceNode.getChildren();
for(WNode buildNode : buildNodes) {
String mainName = buildNode.getAttribute(PreferenceBuild.Fields.mainProblemElement);
String otherName = buildNode.getAttribute(PreferenceBuild.Fields.otherProblemElement);
ProblemElement mainPE = problemService.getByName(mainType, mainName);
ProblemElement otherPE = problemService.getByName(otherType, otherName);
WNode leftNode = buildNode.getFirst(PreferenceBuild.Fields.leftElements);
ArrayList<ProblemElement> leftItems = new ArrayList<>();
for(WNode lNode : leftNode.getChildren()) {
String leftId = lNode.getAttribute(ProblemElement.Fields.name);
ProblemElement pe = problemService.getByName(leftType, leftId);
if(pe == null)
throw new NullPointerException();
leftItems.add(pe);
}
WNode rightNode = buildNode.getFirst(PreferenceBuild.Fields.rightElements);
ArrayList<ProblemElement> rightItems = new ArrayList<>();
for(WNode rNode : rightNode.getChildren()) {
String name = rNode.getAttribute(ProblemElement.Fields.name);
ProblemElement pe = problemService.getByName(rightType, name);
if(pe == null)
throw new NullPointerException();
rightItems.add(pe);
}
PreferenceBuild build = new PreferenceBuild(
mainPE,
otherPE,
leftItems.toArray(new ProblemElement[0]),
rightItems.toArray(new ProblemElement[0])
);
WNode matrixNode = buildNode.getFirst(PreferenceMatrix.Fields.PreferenceMatrix);
List<WNode> preferenceNodes = matrixNode.getChildren();
for(WNode prefNode : preferenceNodes) {
int index = prefNode.getAttributeInt(PreferenceMatrix.Fields.preferenceIndex);
String lName = prefNode.getAttribute(PreferenceBuild.Fields.leftProblemElement);
String rName = prefNode.getAttribute(PreferenceBuild.Fields.rightProblemElement);
ProblemElement leftPe = problemService.getByName(leftType, lName);
ProblemElement rightPe = problemService.getByName(rightType, rName);
build.set(leftPe, rightPe, index);
}
builds.add(build);
}
PreferenceCollection pref = new PreferenceCollection(builds.toArray(new PreferenceBuild[0]));
preferencesService.addOrUpdate(pref);
}
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#write() */
@Override
public void write() throws XMLStreamException {
HashMap<PreferenceCollectionKey, PreferenceCollection> preferences = preferencesService.getAllPreferences();
writer.writeStartElement(PreferenceCollection.Fields.PreferenceCollections.toString());
for( Entry<PreferenceCollectionKey, PreferenceCollection> entry : preferences.entrySet() ) {
PreferenceCollectionKey key = entry.getKey();
PreferenceCollection col = entry.getValue();
writePreferenceCollection(key, col);
}
writer.writeEndElement();
}
private void writePreferenceCollection(PreferenceCollectionKey key, PreferenceCollection pref) throws XMLStreamException {
writer.writeStartElement(PreferenceCollection.Fields.PreferenceCollection.toString());
writer.writeAttribute(PreferenceCollection.Fields.mainType.toString(), key.getMainType());
writer.writeAttribute(PreferenceCollection.Fields.otherType.toString(), key.getOtherType());
writer.writeAttribute(PreferenceCollection.Fields.leftType.toString(), key.getLeftType());
writer.writeAttribute(PreferenceCollection.Fields.rightType.toString(), key.getRightType());
for(ProblemElement main : pref.getAllMainElements())
for(ProblemElement other : pref.getAllOtherElements())
writePreferenceBuild(pref, main, other);
writer.writeEndElement();
}
private void writePreferenceBuild(PreferenceCollection pref, ProblemElement pe1, ProblemElement pe2) throws XMLStreamException {
writer.writeStartElement(PreferenceBuild.Fields.PreferenceBuild.toString());
PreferenceBuild build = pref.getBuild(pe1, pe2);
writer.writeAttribute(PreferenceBuild.Fields.mainProblemElement.toString(), pe1.getName());
writer.writeAttribute(PreferenceBuild.Fields.otherProblemElement.toString(), pe2.getName());
writeBuildLeftelements(build);
writeBuildRightelements(build);
writeBuildMatrix(build);
writer.writeEndElement();
}
private void writeBuildMatrix(PreferenceBuild build) throws XMLStreamException {
writer.writeStartElement(PreferenceMatrix.Fields.PreferenceMatrix.toString());
for(ProblemElement leftItem : build.getLeftElements())
for(ProblemElement rightItem : build.getRightElements())
writePreferences(build, leftItem, rightItem);
writer.writeEndElement();
}
private void writeBuildLeftelements(PreferenceBuild build) throws XMLStreamException {
writer.writeStartElement(PreferenceBuild.Fields.leftElements.toString());
// writer.writeAttribute(PreferenceBuild.Fields.type.toString(), build.getLeftType().toString());
for(ProblemElement element : build.getLeftElements()) {
writer.writeStartElement(ProblemElement.Fields.ProblemElement.toString());
writer.writeAttribute(ProblemElement.Fields.name.toString(), element.getName());
writer.writeEndElement();
}
writer.writeEndElement();
}
private void writeBuildRightelements(PreferenceBuild build) throws XMLStreamException {
writer.writeStartElement(PreferenceBuild.Fields.rightElements.toString());
// writer.writeAttribute(PreferenceBuild.Fields.type.toString(), build.getRightType().toString());
for(ProblemElement element : build.getRightElements()) {
writer.writeStartElement(ProblemElement.Fields.ProblemElement.toString());
writer.writeAttribute(ProblemElement.Fields.name.toString(), element.getName());
writer.writeEndElement();
}
writer.writeEndElement();
}
private void writePreferences(PreferenceBuild pref, ProblemElement left, ProblemElement right) throws XMLStreamException {
int index = pref.get(left, right);
writer.writeStartElement(PreferenceBuild.Fields.Preference.toString());
writer.writeAttribute(PreferenceBuild.Fields.leftProblemElement.toString(), left.getName());
writer.writeAttribute(PreferenceBuild.Fields.rightProblemElement.toString(), right.getName());
writer.writeAttribute(PreferenceMatrix.Fields.preferenceIndex.toString(), index+"");
writer.writeEndElement();
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.gathering.preferences"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "preferences"; //$NON-NLS-1$
}
}
@@ -0,0 +1,182 @@
package flintstones.helper.data.io.modules;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamWriter;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.helper.data.io.interfaces.BaseIO30;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.problemelement.service.IProblemElementService;
/**
* The Class IOProblemElements30.
*/
public class IOProblemElements30 extends BaseIO30 {
/** The problem service. */
@Inject
IProblemElementService problemService;
/** The broker. */
@Inject
IEventBroker broker;
/**
* Instantiates a new IO problem elements 30.
*/
public IOProblemElements30() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
WNode eNode = node.getFirst("experts"); //$NON-NLS-1$
this.readExperts(eNode);
WNode aNode = node.getFirst("alternatives"); //$NON-NLS-1$
this.readAlternatives(aNode);
WNode cNode = node.getFirst("criteria"); //$NON-NLS-1$
this.readCriterions(cNode);
}
/**
* Read expert.
*
* @param node the node
* @param parent the parent
* @return the expert
*/
private Expert readExpert(WNode node) {
String id = node.getAttribute("id"); //$NON-NLS-1$
Expert mainPE = new Expert(id);
// mainPE.setParent(null);
this.problemService.add(mainPE);
this.valid++;
for (WNode item : node.getChildren()) {
Expert childPE = this.readExpert(item);
mainPE.addChildren(childPE);
}
return mainPE;
}
/**
* Read experts.
*
* @param node the node
*/
private void readExperts(WNode node) {
for (WNode item : node.getChildren())
this.readExpert(item);
}
/**
* Read alternative.
*
* @param node the node
* @param parent the parent
* @return the alternative
*/
private Alternative readAlternative(WNode node) {
String id = node.getAttribute("id"); //$NON-NLS-1$
Alternative mainPE = new Alternative(id);
this.problemService.add(mainPE);
this.valid++;
return mainPE;
}
/**
* Read alternatives.
*
* @param node the node
*/
private void readAlternatives(WNode node) {
for (WNode item : node.getChildren())
this.readAlternative(item);
}
/**
* Read criterion.
*
* @param node the node
* @param parent the parent
* @return the criterion
*/
private Criterion readCriterion(WNode node) {
String id = node.getAttribute("id"); //$NON-NLS-1$
boolean cost = (node.getAttribute("cost") //$NON-NLS-1$
.equals("true")) ? true : false; //$NON-NLS-1$
Criterion mainPE = new Criterion(id);
mainPE.setCost(cost);
// mainPE.setParent(null);
this.problemService.add(mainPE);
this.valid++;
for (WNode item : node.getChildren()) {
Criterion childPE = this.readCriterion(item);
mainPE.addChildren(childPE);
}
return mainPE;
}
/**
* Read criterion.
*
* @param node the node
*/
private void readCriterions(WNode node) {
for (WNode item : node.getChildren())
this.readCriterion(item);
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
this.problemService.deleteAll();
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.framework"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "elements"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see
* flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */
@Override
public void setWriter(XMLStreamWriter writer) {
}
}
@@ -0,0 +1,249 @@
package flintstones.helper.data.io.modules;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.problemelement.entities.ProblemElementHelper;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.problemelement.service.IProblemElementService;
/**
* The Class IOProblemElements40.
*/
public class IOProblemElements40 extends BaseIO {
/** The problem service. */
@Inject
IProblemElementService problemService;
/** The broker. */
@Inject
IEventBroker broker;
/**
* Instantiates a new IO problem elements 40.
*/
public IOProblemElements40() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
WNode eNode = node.getFirst(Expert.Fields.Experts);
this.readExperts(eNode);
WNode aNode = node.getFirst(Alternative.Fields.Alternatives);
this.readAlternatives(aNode);
WNode cNode = node.getFirst(Criterion.Fields.Criteria);
this.readCriterions(cNode);
}
/* (non-Javadoc)
*
* @see
* flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */
@Override
public void setWriter(XMLStreamWriter writer) {
this.writer = writer;
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#write() */
@Override
public void write() throws XMLStreamException {
ProblemElement[] items = ProblemElementHelper.getAsUserOrdered(problemService.getMainElements(Expert.Type));
this.writer.writeStartElement(Expert.Fields.Experts.toString());
for (ProblemElement pe : items)
this.writePE(pe);
this.writer.writeEndElement();
this.writer.writeStartElement(Alternative.Fields.Alternatives.toString());
items = ProblemElementHelper.getAsUserOrdered(problemService.getMainElements(Alternative.Type));
for (ProblemElement pe : items)
this.writePE(pe);
this.writer.writeEndElement();
this.writer.writeStartElement(Criterion.Fields.Criteria.toString());
items = ProblemElementHelper.getAsUserOrdered(problemService.getMainElements(Criterion.Type));
for (ProblemElement pe : items)
this.writePE(pe);
this.writer.writeEndElement();
}
/**
* Read expert.
*
* @param node the node
* @param parent the parent
* @return the expert
*/
private Expert readExpert(WNode node) {
String name = node.getAttribute(ProblemElement.Fields.name);
String mail = node.getAttribute(Expert.Fields.mail);
Expert mainPE = new Expert(name);
// mainPE.setParent(null);
mainPE.setMail(mail);
this.problemService.add(mainPE);
this.valid++;
WNode children = node.getFirst(ProblemElement.Fields.children);
if (children != null)
for (WNode item : children.getChildren()) {
Expert childPE = this.readExpert(item);
mainPE.addChildren(childPE);
}
return mainPE;
}
/**
* Write PE.
*
* @param pe the pe
* @throws XMLStreamException the XML stream exception
*/
private void writePE(ProblemElement pe) throws XMLStreamException {
this.writer.writeStartElement(pe.getType());
this.writer.writeAttribute(ProblemElement.Fields.name.toString(), pe.getName());
if (pe.getType().equals(Criterion.Type))
this.writer.writeAttribute(Criterion.Fields.cost.toString(), ((Criterion) pe).isCost() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
if(pe.getType().equals(Expert.Type)) {
Expert e = ((Expert)pe);
if(e.getMail() != null && !e.getMail().equals(""))
writer.writeAttribute(Expert.Fields.mail.toString(), e.getMail());
}
if (pe.hasChildren()) {
this.writer.writeStartElement(ProblemElement.Fields.children.toString());
for (ProblemElement cpe : pe.getChildren())
this.writePE(cpe);
this.writer.writeEndElement();
}
this.writer.writeEndElement();
}
/**
* Read experts.
*
* @param node the node
*/
private void readExperts(WNode node) {
for (WNode item : node.getChildren())
this.readExpert(item);
}
/**
* Read alternative.
*
* @param node the node
* @param parent the parent
* @return the alternative
*/
private Alternative readAlternative(WNode node) {
String name = node.getAttribute(ProblemElement.Fields.name);
Alternative mainPE = new Alternative(name);
this.problemService.add(mainPE);
this.valid++;
return mainPE;
}
/**
* Read alternatives.
*
* @param node the node
*/
private void readAlternatives(WNode node) {
for (WNode item : node.getChildren())
this.readAlternative(item);
}
/**
* Read criterion.
*
* @param node the node
* @param parent the parent
* @return the criterion
*/
private Criterion readCriterion(WNode node) {
String name = node.getAttribute(ProblemElement.Fields.name);
boolean cost = (node.getAttribute(Criterion.Fields.cost)
.equals("true")) ? true : false; //$NON-NLS-1$
Criterion mainPE = new Criterion(name);
mainPE.setCost(cost);
// mainPE.setParent(null);
this.problemService.add(mainPE);
this.valid++;
WNode children = node.getFirst(ProblemElement.Fields.children);
if (children != null)
for (WNode item : children.getChildren()) {
Criterion childPE = this.readCriterion(item);
mainPE.addChildren(childPE);
}
return mainPE;
}
/**
* Read criterion.
*
* @param node the node
*/
private void readCriterions(WNode node) {
for (WNode item : node.getChildren())
this.readCriterion(item);
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
this.problemService.deleteAll();
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.framework.problemelements"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "elements"; //$NON-NLS-1$
}
}
@@ -0,0 +1,120 @@
package flintstones.helper.data.io.modules;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import org.eclipse.e4.core.contexts.IEclipseContext;
import flintstones.entity.problemelement.entities.SortingProfile;
import flintstones.entity.ahpsort.profileassignment.ProfileAssignment;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService;
import flintstones.model.problemelement.service.IProblemElementService;
public class IOProfileAssignment40 extends BaseIO {
@Inject
IProfileAssignmentService profileService;
@Inject
IProblemElementService problemService;
@Inject
IEclipseContext context;
public IOProfileAssignment40() {
}
@Override
public void beforeRead() {
}
@Override
public void read(WNode node) {
if (node == null)
return;
List<WNode> assignments = node.getFirst(ProfileAssignment.Fields.ProfileAssignments).getChildren();
for (WNode assignmentN : assignments) {
String expertName = assignmentN.getAttribute(Expert.Fields.Expert);
Expert e = (Expert) problemService.getByName(Expert.Type, expertName);
String criterionName = assignmentN.getAttribute(Criterion.Fields.Criterion);
Criterion c = (Criterion) problemService.getByName(Criterion.Type, criterionName);
// String domainName = assignmentN.getAttribute(Domain.Fields.Domain);
// AHPSortDomain d = (AHPSortDomain) domainService.getByName(domainName);
List<WNode> profiles = assignmentN.getChildren();
LinkedList<Double> list = new LinkedList<>();
for (WNode profileN : profiles) {
double value = Double.parseDouble(profileN.getAttribute(SortingProfile.Fields.value));
list.add(value);
}
ProfileAssignment pa = profileService.create(e, c);
for (Double val : list) {
SortingProfile profile = new SortingProfile(e, c, val);
pa.addProfile(profile);
}
profileService.addOrUpdate(pa);
}
}
@Override
public String getPhase() {
return "flintstones.resolutionphase.gathering.preferences.assignments";
}
@Override
public String getPart() {
return "assignment";
}
@Override
public void write() throws XMLStreamException {
writer.writeStartElement(ProfileAssignment.Fields.ProfileAssignments.toString());
for (Entry<Expert, HashMap<Criterion, ProfileAssignment>> entry : profileService.getAll().entrySet()) {
String expertName = entry.getKey().getName();
for (Entry<Criterion, ProfileAssignment> entry2 : entry.getValue().entrySet()) {
String criterionName = entry2.getKey().getName();
// String domainName = entry2.getValue().getDomain().getName();
ProfileAssignment pa = entry2.getValue();
writeAssignment(expertName, criterionName, pa);
}
}
writer.writeEndElement();
}
private void writeAssignment(String expert, String criterion, ProfileAssignment assigment)
throws XMLStreamException {
writer.writeStartElement(ProfileAssignment.Fields.ProfileAssignment.toString());
writer.writeAttribute(Expert.Fields.Expert.toString(), expert);
// writer.writeAttribute(Domain.Fields.Domain.toString(), domain);
writer.writeAttribute(Criterion.Fields.Criterion.toString(), criterion);
for (SortingProfile p : assigment.getAllProfiles()) {
writer.writeStartElement(SortingProfile.Fields.SortingProfile.toString());
writer.writeAttribute(SortingProfile.Fields.value.toString(), p.getValue() + "");
writer.writeEndElement();
}
writer.writeEndElement();
}
}
@@ -0,0 +1,92 @@
package flintstones.helper.data.io.modules;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.helper.DoubleHelper;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.ahp.referencepoint.service.IReferencePointService;
import flintstones.model.problemelement.service.IProblemElementService;
public class IOReferencePoints40 extends BaseIO {
@Inject
IProblemElementService problemService;
@Inject
IReferencePointService referenceService;
public IOReferencePoints40() {
}
@Override
public void beforeRead() {
// TODO Auto-generated method stub
}
@Override
public void read(WNode node) {
List<WNode> refPoints = node.getFirst("AHPSortReferencences").getChildren();
for(WNode refPoint : refPoints) {
String cName = refPoint.getAttribute("criterion");
Criterion c = (Criterion) problemService.getByName(Criterion.Type, cName);
ArrayList<Double> points = new ArrayList<>();
for(WNode point : refPoint.getChildren()) {
double min = DoubleHelper.ParseDouble(point.getAttribute("value"));
points.add(min);
}
referenceService.addOrUpdate(c, points.toArray(new Double[0]));
LinkedList<AHPSortReferencencePoint> pointsPE = referenceService.get(c);
for(AHPSortReferencencePoint pointPE: pointsPE)
problemService.add(pointPE);
}
}
@Override
public String getPhase() {
return "flintstones.resolutionphase.gathering.ahp";
}
@Override
public String getPart() {
return "references";
}
@Override
public void write() throws XMLStreamException {
ProblemElement[] criterions = problemService.getAll(Criterion.Type);
writer.writeStartElement("AHPSortReferencences");
for (ProblemElement c : criterions) {
LinkedList<AHPSortReferencencePoint> points = referenceService.get((Criterion) c);
if (points.size() > 0) {
writer.writeStartElement("AHPSortReferencencePoints");
writer.writeAttribute("criterion", c.getName());
for (AHPSortReferencencePoint point : points) {
writer.writeStartElement("ReferencePoint");
writer.writeAttribute("value", point.getValue() + "");
writer.writeEndElement();
}
writer.writeEndElement();
}
}
writer.writeEndElement();
};
}
@@ -0,0 +1,68 @@
package flintstones.helper.data.io.modules;
import java.util.Arrays;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import flintstones.entity.problemelement.entities.SortingClass;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
import flintstones.model.problemelement.service.IProblemElementService;
public class IOSortingClass40 extends BaseIO {
@Inject
IProblemElementService problemService;
public IOSortingClass40() {
}
@Override
public void beforeRead() {
// TODO Auto-generated method stub
}
@Override
public void write() throws XMLStreamException {
SortingClass[] classes = Arrays.stream( problemService.getAll(SortingClass.Type)).map(k -> (SortingClass)k).toArray(SortingClass[]::new);
for (SortingClass classItem : classes) {
writer.writeStartElement("SortingClass");
writer.writeAttribute(SortingClass.Fields.name.toString(), classItem.getName());
writer.writeEndElement();
}
};
@Override
public void read(WNode node) {
if(node == null)
return ;
WNode[] nodes = node.getChildren().toArray(new WNode[0]);
for (WNode wnode : nodes) {
String name = wnode.getAttribute(SortingClass.Fields.name);
SortingClass ahpClass = new SortingClass(name);
problemService.add(ahpClass);
}
}
@Override
public String getPhase() {
return "flintstones.resolutionphase.framework.problemelements.sorting";
}
@Override
public String getPart() {
return "sorting";
}
}
@@ -0,0 +1,129 @@
package flintstones.helper.data.io.modules;
import java.util.List;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamWriter;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.problemelement.ProblemElementKey;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.io.interfaces.BaseIO30;
import flintstones.helper.data.wxml.WNode;
import flintstones.helper.debug.DH;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
/**
* The Class IOValuation30.
*/
public class IOValuation30 extends BaseIO30 {
/** The valuation service. */
@Inject
IValuationService valuationService;
/** The problem service. */
@Inject
IProblemElementService problemService;
/** The domain service. */
@Inject
IDomainService domainService;
/** The broker. */
@Inject
IEventBroker broker;
/**
* Instantiates a new IO valuation 30.
*/
public IOValuation30() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
List<WNode> nodes = node.getChildren();
this.expected = nodes.size();
for (WNode item : nodes) {
String expertCanonicalName = item.getAttribute("expert"); //$NON-NLS-1$
String alternativeCanonicalName = item.getAttribute("alternative"); //$NON-NLS-1$
String criterionCanonicalName = item.getAttribute("criterion"); //$NON-NLS-1$
Expert expert = (Expert) this.problemService.getByCanonicalName(Expert.Type, expertCanonicalName);
Alternative alternative = (Alternative) this.problemService.getByCanonicalName(Alternative.Type, alternativeCanonicalName);
Criterion criterion = (Criterion) this.problemService.getByCanonicalName(Criterion.Type, criterionCanonicalName);
if (expert == null) {
DH.out("!ERRORFS El experto " + expertCanonicalName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$
this.failed++;
continue;
}
if (alternative == null) {
DH.out("!ERRORFS La alternativa " + alternativeCanonicalName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$
this.failed++;
continue;
}
if (criterion == null) {
DH.out("!ERRORFS El criterio " + criterionCanonicalName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$
this.failed++;
continue;
}
ProblemElementKey pek = new ProblemElementKey(expert, alternative, criterion);
Valuation valuation = this.valuationService.getValuationFor(pek);
valuation.read(item);
valuation.setEvaluated(true);
this.valuationService.addOrUpdate(pek, valuation);
this.valid++;
}
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.gathering"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "valuations"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see
* flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */
@Override
public void setWriter(XMLStreamWriter writer) {
}
}
@@ -0,0 +1,156 @@
package flintstones.helper.data.io.modules;
import java.util.List;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import org.eclipse.e4.core.services.events.IEventBroker;
import flintstones.entity.problemelement.ProblemElementKey;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.io.interfaces.BaseIO;
import flintstones.helper.data.wxml.WNode;
import flintstones.helper.debug.DH;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
/**
* The Class IOValuation40.
*/
public class IOValuation40 extends BaseIO {
/** The valuation service. */
@Inject
IValuationService valuationService;
/** The problem service. */
@Inject
IProblemElementService problemService;
/** The domain service. */
@Inject
IDomainService domainService;
/** The broker. */
@Inject
IEventBroker broker;
/**
* Instantiates a new IO valuation 40.
*/
public IOValuation40() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */
@Override
public void read(WNode node) {
List<WNode> nodes = node.getChildren();
this.expected = nodes.size();
for (WNode item : nodes) {
String expertName = item.getAttribute(Expert.Fields.Expert.toString());
String alternativeName = item.getAttribute(Alternative.Fields.Alternative.toString());
String criterionName = item.getAttribute(Criterion.Fields.Criterion.toString());
Expert expert = (Expert) this.problemService.getByName(Expert.Fields.Expert.toString(), expertName);
Alternative alternative = (Alternative) this.problemService.getByName(Alternative.Fields.Alternative.toString(), alternativeName);
Criterion criterion = (Criterion) this.problemService.getByName(Criterion.Fields.Criterion.toString(), criterionName);
if (expert == null) {
DH.out("!ERRORFS El experto " + expertName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$
this.failed++;
continue;
}
if (alternative == null) {
DH.out("!ERRORFS La alternativa " + alternativeName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$
this.failed++;
continue;
}
if (criterion == null) {
DH.out("!ERRORFS El criterio " + criterionName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$
this.failed++;
continue;
}
ProblemElementKey pek = new ProblemElementKey(expert, alternative, criterion);
Valuation valuation = this.valuationService.getValuationFor(pek);
valuation.read(item);
valuation.setEvaluated(true);
this.valuationService.addOrUpdate(pek, valuation);
this.valid++;
}
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#write() */
@Override
public void write() throws XMLStreamException {
for (Entry<ProblemElementKey, Valuation> entry : this.valuationService.getAllKV()
.entrySet())
this.writeValuation(entry.getKey(), entry.getValue());
}
private void writeValuation(ProblemElementKey pek, Valuation v) throws XMLStreamException {
if (!v.isEvaluated())
return;
this.writer.writeStartElement(Valuation.Fields.Valuation.toString());
this.writer.writeAttribute(Valuation.Fields.type.toString(), v.getClass()
.getName());
this.writer.writeAttribute(Valuation.Fields.domain.toString(), v.getDomain()
.getName());
this.writer.writeAttribute(Alternative.Fields.Alternative.toString(), pek.getAlternative()
.getName());
this.writer.writeAttribute(Criterion.Fields.Criterion.toString(), pek.getCriterion()
.getName());
this.writer.writeAttribute(Expert.Fields.Expert.toString(), pek.getExpert()
.getName());
v.write(this.writer);
this.writer.writeEndElement();
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#beforeRead() */
@Override
public void beforeRead() {
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPhase() */
@Override
public String getPhase() {
return "flintstones.resolutionphase.gathering"; //$NON-NLS-1$
}
/* (non-Javadoc)
*
* @see flintstones.helper.data.io.BaseIO#getPart() */
@Override
public String getPart() {
return "valuations"; //$NON-NLS-1$
}
}