Commit 3006f883 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

clena tmp resource

parent 7c5f2703
......@@ -16,7 +16,9 @@
*/
package org.bonitasoft.studio.condition.ui.expression;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -406,7 +408,13 @@ public class ComparisonExpressionEditor extends SelectionAwareExpressionEditor i
*/
@Override
public void dispose() {
if (resource != null) {
try {
resource.delete(Collections.emptyMap());
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
}
}
/*
......
......@@ -65,7 +65,7 @@ public class XtextComparisonExpressionLoader {
}
protected IFile createTmpFile(final String content, final IProject project) throws UnsupportedEncodingException, CoreException {
final IFile file = project.getFile("somefile" + System.currentTimeMillis() + ".cmodel");
final IFile file = project.getFile("somefile.cmodel");
if (file.exists()) {
file.delete(true, null);
}
......
......@@ -16,9 +16,13 @@
*/
package org.bonitasoft.studio.engine.export.expression.converter.comparison;
import java.io.IOException;
import java.util.Collections;
import org.bonitasoft.engine.expression.ExpressionBuilder;
import org.bonitasoft.engine.expression.InvalidExpressionException;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.condition.conditionModel.Operation_Compare;
import org.bonitasoft.studio.condition.conditionModel.Operation_NotUnary;
import org.bonitasoft.studio.condition.conditionModel.Unary_Operation;
......@@ -50,12 +54,10 @@ public class ComparisonExpressionConverter implements IExpressionConverter {
final ExpressionBuilder expressionBuilder = new ExpressionBuilder();
final String name = getExpressionName(expression);
final String content = expression.getContent();
Operation_Compare compare;
Operation_Compare compare = null;
try {
compare = expressionLoader.loadConditionExpression(content, expression.eContainer());
} catch (final ComparisonExpressionLoadException e) {
throw new InvalidExpressionException("Failed to load comparison expression");
}
if (compare != null && compare.getOp() != null) {
final EObject op = compare.getOp();
if (op instanceof Unary_Operation) {
......@@ -65,6 +67,17 @@ public class ComparisonExpressionConverter implements IExpressionConverter {
}
}
return null;
} catch (final ComparisonExpressionLoadException e) {
throw new InvalidExpressionException("Failed to load comparison expression");
} finally {
if (compare != null && compare.eResource() != null) {
try {
compare.eResource().delete(Collections.emptyMap());
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
}
}
}
......
......@@ -27,9 +27,6 @@ import org.bonitasoft.studio.engine.export.EngineExpressionUtil;
import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.process.Data;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.EcoreUtil2;
/**
* @author Romain Bioteau
......@@ -37,40 +34,40 @@ import org.eclipse.xtext.EcoreUtil2;
*/
public class ExpressionConditionModelSwitch extends ConditionModelSwitch<Expression> {
private org.bonitasoft.studio.model.expression.Expression studioExpression;
private final org.bonitasoft.studio.model.expression.Expression studioExpression;
public ExpressionConditionModelSwitch(org.bonitasoft.studio.model.expression.Expression studioExpression){
public ExpressionConditionModelSwitch(final org.bonitasoft.studio.model.expression.Expression studioExpression){
this.studioExpression = studioExpression;
}
@Override
public Expression caseExpression_Boolean(Expression_Boolean object) {
public Expression caseExpression_Boolean(final Expression_Boolean object) {
return EngineExpressionUtil.createConstantExpression(String.valueOf(object.isValue()),String.valueOf(object.isValue()),Boolean.class.getName());
}
@Override
public Expression caseExpression_Double(Expression_Double object) {
public Expression caseExpression_Double(final Expression_Double object) {
return EngineExpressionUtil.createConstantExpression(String.valueOf(object.getValue()),String.valueOf(object.getValue()),Double.class.getName());
}
@Override
public Expression caseExpression_Integer(Expression_Integer object) {
public Expression caseExpression_Integer(final Expression_Integer object) {
return EngineExpressionUtil.createConstantExpression(String.valueOf(object.getValue()),String.valueOf(object.getValue()),Long.class.getName());
}
@Override
public Expression caseExpression_String(Expression_String object) {
String value = object.getValue();
public Expression caseExpression_String(final Expression_String object) {
final String value = object.getValue();
if (value==null || value.isEmpty()){
return EngineExpressionUtil.createConstantExpression("<empty-string>","",String.class.getName());
}
return EngineExpressionUtil.createConstantExpression(value,value,String.class.getName());
}
@Override
public Expression caseExpression_ProcessRef(Expression_ProcessRef object) {
EObject resolvedProxy = resolveProxy(object.getValue());
for(EObject dep : studioExpression.getReferencedElements()){
public Expression caseExpression_ProcessRef(final Expression_ProcessRef object) {
final EObject resolvedProxy = object.getValue();
for(final EObject dep : studioExpression.getReferencedElements()){
if(dep instanceof Data && resolvedProxy instanceof Data){
if(((Data) dep).getName().equals(((Data) resolvedProxy).getName())){
return EngineExpressionUtil.createVariableExpression((Data) dep);
......@@ -83,17 +80,6 @@ public class ExpressionConditionModelSwitch extends ConditionModelSwitch<Express
}
return null;
}
private EObject resolveProxy(EObject ref) {
ResourceSet rSet = null;
if(ref.eIsProxy() && EcoreUtil.getURI(ref).lastSegment().endsWith(".proc")){
rSet = studioExpression.eResource().getResourceSet();
}
EObject dep = EcoreUtil2.resolve(ref, rSet);
if(rSet != null){
rSet.getResources().remove(ref.eResource());
}
return dep;
}
}
......@@ -17,7 +17,11 @@
*/
package org.bonitasoft.studio.validation.constraints.process;
import java.io.IOException;
import java.util.Collections;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.condition.conditionModel.Operation_Compare;
import org.bonitasoft.studio.condition.ui.expression.ComparisonExpressionLoadException;
import org.bonitasoft.studio.condition.ui.expression.XtextComparisonExpressionLoader;
......@@ -69,6 +73,13 @@ public class ConditionExpressionConstraint extends AbstractLiveValidationMarkerC
if(opCompare == null || opCompare.getOp() == null){
return ctx.createFailureStatus(Messages.bind(Messages.invalidConditionExpression,conditionExpression.getName()));
}
if (opCompare != null && opCompare.eResource() != null) {
try {
opCompare.eResource().delete(Collections.emptyMap());
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
}
}
}
return ctx.createSuccessStatus();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment