public code v1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?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.model.valuation.provider</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Provider</name>
|
||||
</project>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.model.valuation.provider</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.pde.ds.core.builder</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>1779484362730</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>
|
||||
+2
@@ -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,26 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Provider
|
||||
Bundle-SymbolicName: flintstones.model.valuation.provider
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.model.valuation.provider
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: flintstones.helper.extensionpoint,
|
||||
org.eclipse.e4.core.contexts,
|
||||
org.eclipse.e4.core.di,
|
||||
org.eclipse.e4.ui.model.workbench,
|
||||
javax.inject,
|
||||
javax.annotation,
|
||||
flintstones.entity.problemelement,
|
||||
flintstones.entity.valuation,
|
||||
flintstones.entity.domain,
|
||||
org.eclipse.e4.ui.di,
|
||||
flintstones.application.constants,
|
||||
flintstones.model.valuation.service,
|
||||
org.eclipse.e4.ui.model.workbench,
|
||||
javax.annotation,
|
||||
flintstones.model.problemelement.service,
|
||||
flintstones.model.domain.service,
|
||||
flintstones.helper.debug
|
||||
Service-Component: component.xml
|
||||
Bundle-ActivationPolicy: lazy
|
||||
@@ -0,0 +1,5 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
component.xml
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="flintstones.valuation">
|
||||
<implementation class="flintstones.model.valuation.provider.ValuationServiceContextFunction" />
|
||||
<property name="service.context.key" type="String" value="flintstones.model.valuation.service.IValuationService" />
|
||||
<service>
|
||||
<provide interface="org.eclipse.e4.core.contexts.IContextFunction" />
|
||||
</service>
|
||||
|
||||
</scr:component>
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package flintstones.model.valuation.provider;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextFunction;
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.ui.model.application.MApplication;
|
||||
|
||||
import flintstones.model.valuation.service.IValuationService;
|
||||
|
||||
|
||||
/**
|
||||
* The Class ValuationServiceContextFunction add the Valuation Service instance to global context.
|
||||
*/
|
||||
public class ValuationServiceContextFunction extends ContextFunction {
|
||||
|
||||
@Override
|
||||
public Object compute(IEclipseContext context, String contextKey) {
|
||||
IValuationService service = ContextInjectionFactory.make(ValuationServiceProvider.class, context);
|
||||
MApplication application = context.get(MApplication.class);
|
||||
IEclipseContext applicationContext = application.getContext();
|
||||
applicationContext.set(IValuationService.class, service);
|
||||
return service;
|
||||
}
|
||||
|
||||
}
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
package flintstones.model.valuation.provider;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.ui.di.UIEventTopic;
|
||||
|
||||
import flintstones.application.constants.FrameworkConstants;
|
||||
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.problemelement.entities.ProblemElement;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.extensionpoint.BaseRegistry;
|
||||
import flintstones.helper.extensionpoint.BaseRegistry.InvalidExtensionIdentifier;
|
||||
import flintstones.helper.extensionpoint.ExtensionRegistry;
|
||||
import flintstones.model.domain.service.IDomainService;
|
||||
import flintstones.model.problemelement.service.IProblemElementService;
|
||||
import flintstones.model.valuation.service.IValuationService;
|
||||
|
||||
/**
|
||||
* @author Sinbad2
|
||||
*
|
||||
*/
|
||||
class ValuationServiceProvider implements IValuationService {
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
@Inject
|
||||
IProblemElementService problemService;
|
||||
|
||||
@Inject
|
||||
IDomainService domainService;
|
||||
|
||||
private BaseRegistry reg;
|
||||
|
||||
private LinkedHashMap<ProblemElementKey, Valuation> valuationsK = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Valuation Service
|
||||
*/
|
||||
public ValuationServiceProvider() {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
this.reg = new BaseRegistry(Valuation.EXTENSION_POINT);
|
||||
this.valuationsK = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Valuation[] getAll() {
|
||||
return this.valuationsK.values().toArray(new Valuation[this.valuationsK.values().size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedHashMap<ProblemElementKey, Valuation> getAllKV() {
|
||||
return this.valuationsK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExtensionIdFor(String domainType) {
|
||||
ExtensionRegistry[] eArr = this.reg.getAllRegistriesWhere(Valuation.Fields.domain, domainType);
|
||||
for (ExtensionRegistry e : eArr)
|
||||
if (!e.getAttributeBoolean(Valuation.Fields.is_intermediate))
|
||||
return e.getAttribute(Valuation.Fields.uid);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDomainFor(String valuationId) {
|
||||
return this.reg.getFirstRegistryWhere(Valuation.Fields.uid, valuationId).getAttribute(Valuation.Fields.domain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExtensionNameFor(String domainType) {
|
||||
ExtensionRegistry[] eArr = this.reg.getAllRegistriesWhere(Valuation.Fields.domain, domainType);
|
||||
for (ExtensionRegistry e : eArr)
|
||||
if (!e.getAttributeBoolean(Valuation.Fields.is_intermediate))
|
||||
return e.getAttribute(Valuation.Fields.name);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Valuation create(Domain d) {
|
||||
String domainId = d.getType();
|
||||
String valuationId = getExtensionIdFor(domainId);
|
||||
Valuation valuation = null;
|
||||
try {
|
||||
if(valuationId == null)
|
||||
return null;
|
||||
valuation = (Valuation) this.reg.instantiate(valuationId, this.context);
|
||||
valuation.setId(valuationId);
|
||||
valuation.setName(this.reg.getFirstRegistryWhere(Valuation.Fields.uid, valuationId)
|
||||
.getAttribute(Valuation.Fields.name));
|
||||
valuation.setDomain(d);
|
||||
|
||||
} catch (InvalidExtensionIdentifier e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return valuation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOrUpdate(ProblemElementKey pek, Valuation v) {
|
||||
if (pek.getCriterion().hasChildren()) {
|
||||
throw new RuntimeException("No se permiten pek con child " + pek.getCriterion().getName());
|
||||
}
|
||||
|
||||
if (pek.getExpert().hasChildren()) {
|
||||
throw new RuntimeException("No se permiten pek con child" + pek.getExpert().getName());
|
||||
}
|
||||
|
||||
this.valuationsK.put(pek, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Valuation[] getAllValuationsWith(ProblemElement item) {
|
||||
|
||||
String type = item.getType();
|
||||
|
||||
return this.valuationsK.entrySet().stream().filter(k -> k.getKey().get(type).getName().equals(item.getName()))
|
||||
.map(k -> k.getValue()).toArray(Valuation[]::new);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<ProblemElementKey, Valuation> getAllValuationsKVWith(ProblemElement item) {
|
||||
|
||||
String type = item.getType();
|
||||
HashMap<ProblemElementKey, Valuation> result = new HashMap<>();
|
||||
|
||||
this.valuationsK.entrySet().stream().filter(k -> k.getKey().get(type).getName().equals(item.getName()))
|
||||
.forEach(entry -> result.put(entry.getKey(), entry.getValue()));
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Valuation getValuationFor(ProblemElementKey pek) {
|
||||
return this.valuationsK.get(pek);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValuationFor(Domain domain) {
|
||||
|
||||
List<ProblemElementKey> peks = this.valuationsK.entrySet().stream()
|
||||
// Filter the valuation with the searched domain
|
||||
.filter(k -> k.getValue().getDomain().getName().equals(domain.getName()))
|
||||
// Map KEY,VALUE -> KEY
|
||||
.map(k2 -> k2.getKey())
|
||||
// To a list, we cannot modify the DE that we are reading
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Delete all of them
|
||||
peks.forEach(k3 -> this.valuationsK.remove(k3));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValuationFor(String type, ProblemElement item) {
|
||||
|
||||
List<ProblemElementKey> peksToRemove = new LinkedList<ProblemElementKey>();
|
||||
for(ProblemElementKey pek: this.valuationsK.keySet()) {
|
||||
if(pek.get(type) != null) {
|
||||
if(pek.get(type).getName().equals(item.getName()))
|
||||
peksToRemove.add(pek);
|
||||
}
|
||||
}
|
||||
|
||||
peksToRemove.forEach(k3 -> this.valuationsK.remove(k3));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.valuationsK.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Entry<ProblemElementKey, Valuation> entry : valuationsK.entrySet())
|
||||
sb.append((entry.getValue().isEvaluated() ? "V" : "X") + " | " + entry.getKey().toString() + " ==> "
|
||||
+ entry.getValue() + " | " + entry.getValue().getId() + "\n");
|
||||
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignmentFilled() {
|
||||
|
||||
ProblemElement[] experts = problemService.getSubElements(Expert.Type);
|
||||
ProblemElement[] criterions = problemService.getSubElements(Criterion.Type);
|
||||
ProblemElement[] alternatives = problemService.getAll(Alternative.Type);
|
||||
|
||||
for (ProblemElement e : experts)
|
||||
for (ProblemElement c : criterions)
|
||||
for (ProblemElement a : alternatives)
|
||||
if (getValuationFor(new ProblemElementKey((Expert) e, (Alternative) a, (Criterion) c)) == null)
|
||||
return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEvaluationFilled() {
|
||||
|
||||
if (!isAssignmentFilled())
|
||||
return false;
|
||||
|
||||
ProblemElement[] experts = problemService.getSubElements(Expert.Type);
|
||||
ProblemElement[] criterions = problemService.getSubElements(Criterion.Type);
|
||||
ProblemElement[] alternatives = problemService.getAll(Alternative.Type);
|
||||
|
||||
for (ProblemElement e : experts)
|
||||
for (ProblemElement c : criterions)
|
||||
for (ProblemElement a : alternatives)
|
||||
if (!getValuationFor(new ProblemElementKey((Expert) e, (Alternative) a, (Criterion) c))
|
||||
.isEvaluated())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValuation(ProblemElementKey pek) {
|
||||
// Create a new one.
|
||||
Valuation v = valuationsK.get(pek);
|
||||
v = create(v.getDomain());
|
||||
valuationsK.put(pek, v);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Optional
|
||||
private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_DELETED) Domain d) {
|
||||
|
||||
for (Entry<ProblemElementKey, Valuation> entry : this.getAllKV().entrySet()) {
|
||||
ProblemElementKey pek = entry.getKey();
|
||||
Valuation v = entry.getValue();
|
||||
|
||||
if (v.getDomain().equals(d)) {
|
||||
this.valuationsK.remove(pek);
|
||||
v.setDomain(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user