
com.ecfeed.core.operations.BulkOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ecfeed.junit Show documentation
Show all versions of ecfeed.junit Show documentation
An open library used to connect to the ecFeed service. It can be also used as a standalone testing tool. It is integrated with Junit5 and generates a stream of test cases using a selected algorithm (e.g. Cartesian, N-Wise). There are no limitations associated with the off-line version but the user cannot access the on-line computation servers and the model database.
The newest version!
/*******************************************************************************
*
* Copyright (c) 2016 ecFeed AS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package com.ecfeed.core.operations;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.ecfeed.core.model.AbstractNode;
import com.ecfeed.core.model.ModelOperationException;
public class BulkOperation extends AbstractModelOperation {
List fOperations;
List fExecutedOperations;
// either all operation or none. if false, all operations are executed
// otherwise after first error the reverse operation is called
private final boolean fAtomic;
private final List fCheckOperations;
private AbstractNode fNodeToSelectAfterReverseOperation;
protected interface ICheckOperation {
public void check() throws ModelOperationException;
}
public BulkOperation(
String name,
boolean atomic,
AbstractNode nodeToSelect,
AbstractNode nodeToSelectAfterReverseOperation) {
this(name, new ArrayList(), atomic,
nodeToSelect, nodeToSelectAfterReverseOperation);
}
public BulkOperation(
String name,
List operations,
boolean atomic,
AbstractNode nodeToSelect,
AbstractNode nodeToelectAfterReverseOperation) {
super(name);
fOperations = operations;
fExecutedOperations = new ArrayList();
fCheckOperations = new ArrayList();
fAtomic = atomic;
setOneNodeToSelect(nodeToSelect);
fNodeToSelectAfterReverseOperation = nodeToelectAfterReverseOperation;
}
protected void addOperation(IModelOperation operation) {
fOperations.add(operation);
}
protected void addCheckOperation(ICheckOperation operation) {
fCheckOperations.add(operation);
}
public static final String PROBLEM_WITH_BULK_OPERATION(String operation) {
return "Cannot perform operation: " + operation;
}
@Override
public void execute() throws ModelOperationException {
Set errors = new HashSet();
fExecutedOperations.clear();
for (IModelOperation operation : fOperations) {
try {
operation.execute();
fExecutedOperations.add(operation);
} catch(ModelOperationException e) {
errors.add(e.getMessage());
if(fAtomic) {
getReverseOperation().execute();
break;
}
}
}
for (ICheckOperation operation : fCheckOperations) {
try {
operation.check();
} catch(ModelOperationException e) {
errors.add(e.getMessage());
getReverseOperation().execute();
break;
}
}
if (errors.size() > 0) {
String message = PROBLEM_WITH_BULK_OPERATION(getName());
for(String error : errors) {
message += "\n" + error;
}
ModelOperationException.report(message);
}
}
@Override
public IModelOperation getReverseOperation() {
return new BulkOperation(
"reverse " + getName(), reverseOperations(),
fAtomic, fNodeToSelectAfterReverseOperation, null);
}
protected List operations() {
return fOperations;
}
protected List executedOperations() {
return fExecutedOperations;
}
protected List reverseOperations() {
List reverseOperations = new ArrayList();
for(IModelOperation operation : executedOperations()){
reverseOperations.add(0, operation.getReverseOperation());
}
return reverseOperations;
}
@Override
public boolean modelUpdated() {
for (IModelOperation operation : fExecutedOperations) {
if (operation.modelUpdated()) {
return true;
}
}
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy