Commit 09cd8257 authored by Adrien's avatar Adrien Committed by GitHub

feat(data management) manage single document (#1579)

* feat(data management) manage single document

closes [BST-90](https://bonitasoft.atlassian.net/browse/BST-90)
parent 1a6e70df
......@@ -5,12 +5,10 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -19,6 +17,7 @@ package org.bonitasoft.studio.contract.core.operation;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.all;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.bonitasoft.studio.model.process.builders.ContractBuilder.aContract;
import static org.bonitasoft.studio.model.process.builders.ContractInputBuilder.aContractInput;
......@@ -150,9 +149,11 @@ public class ToWebContractTest {
final ToWebContract contractConverter = new ToWebContract();
final Contract contract = contractConverter.apply(aContract()
.havingInput(aContractInput().withType(ContractInputType.FILE)).build());
.havingInput(aContractInput().withType(ContractInputType.FILE).withDataReference("myDocument")).build());
assertThat(contract.getInput()).extracting("type").containsExactly(File.class.getName());
assertThat(contract.getInput()).extracting("dataReference.name", "dataReference.type")
.containsExactly(tuple("myDocument", File.class.getName()));
}
@Test
......@@ -189,4 +190,3 @@ public class ToWebContractTest {
assertThat(contract.getInput()).extracting("type").containsExactly(Long.class.getName());
}
}
......@@ -374,6 +374,34 @@ public class ContractInputGenerationWizardTest {
assertThat(wizard.canFinish()).isTrue();
}
@Test
public void should_add_data_reference_for_document_only_on_task() {
Task task = aTask().havingContract(aContract()).build();
Pool process = aPool().havingContract(aContract()).build();
Document document1 = ProcessFactory.eINSTANCE.createDocument();
document1.setName("myDocument");
process.getDocuments().add(document1);
process.getElements().add(task);
ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(),
repositoryAccessor, operationBuilder,
expressionBuilder,
preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(),
sourceViewerFactory);
wizard.addPages();
assertThat(wizard.createDocumentContractInput(document1).getDataReference()).isNull();
wizard = new ContractInputGenerationWizard(task, editingDomain(),
repositoryAccessor, operationBuilder,
expressionBuilder,
preferenceStore, sharedImages, dialogFactory, new ContractInputGenerationWizardPagesFactory(),
sourceViewerFactory);
wizard.addPages();
assertThat(wizard.createDocumentContractInput(document1).getDataReference()).isEqualTo("myDocument");
}
private EditingDomain editingDomain() {
return new TransactionalEditingDomainImpl(new ProcessItemProviderAdapterFactory());
}
......
......@@ -21,9 +21,9 @@ import org.bonitasoft.studio.contract.core.mapping.SimpleFieldToContractInputMap
import org.bonitasoft.studio.model.process.BusinessObjectData;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.studio.model.process.ContractInputType;
import org.bonitasoft.web.designer.model.contract.DataReference;
import org.bonitasoft.web.designer.model.contract.DataReference.LoadingType;
import org.bonitasoft.web.designer.model.contract.DataReference.RelationType;
import org.bonitasoft.web.designer.model.contract.BusinessDataReference;
import org.bonitasoft.web.designer.model.contract.BusinessDataReference.LoadingType;
import org.bonitasoft.web.designer.model.contract.BusinessDataReference.RelationType;
public class TreeBuilder {
......@@ -39,7 +39,7 @@ public class TreeBuilder {
.orElseThrow(() -> new IllegalStateException(
String.format("No Business Object found with type %s", data.getClassName())));
TreeNode node = new TreeNode(input,
new DataReference(data.getName(), data.getClassName(), RelationType.COMPOSITION, LoadingType.EAGER));
new BusinessDataReference(data.getName(), data.getClassName(), RelationType.COMPOSITION, LoadingType.EAGER));
buildTree(bo, input, node);
return node;
}
......@@ -62,7 +62,7 @@ public class TreeBuilder {
.ifPresent(field -> {
RelationField relationField = (RelationField) field;
BusinessObject businessObject = relationField.getReference();
TreeNode newNode = node.addNode(childInput, new DataReference(relationField.getName(),
TreeNode newNode = node.addNode(childInput, new BusinessDataReference(relationField.getName(),
businessObject.getQualifiedName(),
toRelationType(relationField),
toLoadingType(relationField)));
......
......@@ -26,10 +26,12 @@ import java.util.Date;
import org.bonitasoft.studio.contract.core.mapping.treeMaching.TreeResult;
import org.bonitasoft.studio.model.process.Contract;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.web.designer.model.contract.DataReference;
import org.bonitasoft.web.designer.model.contract.LeafContractInput;
import org.bonitasoft.web.designer.model.contract.NodeContractInput;
import com.google.common.base.Function;
import com.google.common.base.Strings;
public class ToWebContract implements Function<Contract, org.bonitasoft.web.designer.model.contract.Contract> {
......@@ -38,7 +40,7 @@ public class ToWebContract implements Function<Contract, org.bonitasoft.web.desi
public ToWebContract(TreeResult treeResult) {
this.treeResult = treeResult;
}
public ToWebContract() {
this(new TreeResult());
}
......@@ -75,7 +77,7 @@ public class ToWebContract implements Function<Contract, org.bonitasoft.web.desi
case BOOLEAN:
return createLeafContractInput(input, Boolean.class);
case FILE:
return createLeafContractInput(input, File.class);
return createDocumentLeafContractInput(input);
case COMPLEX:
return createNodeContractInput(input);
default:
......@@ -90,11 +92,22 @@ public class ToWebContract implements Function<Contract, org.bonitasoft.web.desi
return copyInputProperties(input, new LeafContractInput(input.getName(), type));
}
private org.bonitasoft.web.designer.model.contract.ContractInput createDocumentLeafContractInput(
final ContractInput input) {
org.bonitasoft.web.designer.model.contract.ContractInput leafContractInput = createLeafContractInput(input,
File.class);
if (!Strings.isNullOrEmpty(input.getDataReference())) {
((LeafContractInput) leafContractInput)
.setDataReference(new DataReference(input.getDataReference(), File.class.getName()));
}
return leafContractInput;
}
private org.bonitasoft.web.designer.model.contract.ContractInput copyInputProperties(final ContractInput input,
final org.bonitasoft.web.designer.model.contract.ContractInput contractInput) {
contractInput.setMultiple(input.isMultiple());
contractInput.setDescription(input.getDescription());
if(contractInput instanceof NodeContractInput) {
if (contractInput instanceof NodeContractInput) {
((NodeContractInput) contractInput).setDataReference(treeResult.getDataReference(input));
}
return contractInput;
......
......@@ -252,35 +252,38 @@ public class ContractInputGenerationWizard extends Wizard {
return true;
}
private IRunnableWithProgress buildContractOperationFromDocument(final Document document) {
return new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("", IProgressMonitor.UNKNOWN);
final ContractInput input = ProcessFactory.eINSTANCE.createContractInput();
input.setType(ContractInputType.FILE);
input.setMultiple(document.isMultiple());
input.setName(selectBusinessDataWizardPage.getRootName());
input.setDataReference(document.getName());
final CompoundCommand cc = new CompoundCommand();
cc.append(AddCommand.create(editingDomain, contractContainer.getContract(),
ProcessPackage.Literals.CONTRACT__INPUTS,
input));
if (contractContainer instanceof Task) {
createDocumentUpdateOperation(document, input, cc);
} else {
cc.append(SetCommand.create(editingDomain, document, ProcessPackage.Literals.DOCUMENT__DOCUMENT_TYPE,
DocumentType.CONTRACT));
cc.append(
SetCommand.create(editingDomain, document, ProcessPackage.Literals.DOCUMENT__CONTRACT_INPUT,
input));
}
editingDomain.getCommandStack().execute(cc);
private IRunnableWithProgress buildContractOperationFromDocument(Document document) {
return monitor -> {
monitor.beginTask("", IProgressMonitor.UNKNOWN);
ContractInput input = createDocumentContractInput(document);
CompoundCommand cc = new CompoundCommand();
cc.append(AddCommand.create(editingDomain, contractContainer.getContract(),
ProcessPackage.Literals.CONTRACT__INPUTS,
input));
if (contractContainer instanceof Task) {
createDocumentUpdateOperation(document, input, cc);
} else {
cc.append(SetCommand.create(editingDomain, document, ProcessPackage.Literals.DOCUMENT__DOCUMENT_TYPE,
DocumentType.CONTRACT));
cc.append(
SetCommand.create(editingDomain, document, ProcessPackage.Literals.DOCUMENT__CONTRACT_INPUT,
input));
}
editingDomain.getCommandStack().execute(cc);
};
}
protected ContractInput createDocumentContractInput(Document document) {
ContractInput input = ProcessFactory.eINSTANCE.createContractInput();
input.setType(ContractInputType.FILE);
input.setMultiple(document.isMultiple());
input.setName(selectBusinessDataWizardPage.getRootName());
if (contractContainer instanceof Task) {
input.setDataReference(document.getName());
}
return input;
}
private void createDocumentUpdateOperation(final Document document, final ContractInput input,
final CompoundCommand cc) {
final Operation operation = ExpressionFactory.eINSTANCE.createOperation();
......
......@@ -14,7 +14,7 @@
<tychoExtrasVersion>1.3.0</tychoExtrasVersion>
<os-jvm-flags></os-jvm-flags>
<bundle.version>${project.version}</bundle.version>
<ui.designer.version>1.9.14</ui.designer.version>
<ui.designer.version>1.9.15</ui.designer.version>
<engine.version>${project.version}</engine.version>
<filters.version>${project.version}</filters.version>
<platform.version>${project.parent.version}</platform.version>
......
Markdown is supported
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