Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / test / java / eu / etaxonomy / taxeditor / store / operations / RemotingTestUpdateOperation.java
1 /**
2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.store.operations;
10
11 import org.eclipse.core.runtime.IAdaptable;
12 import org.eclipse.core.runtime.IProgressMonitor;
13
14 import eu.etaxonomy.cdm.api.application.CdmApplicationState;
15 import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
16 import eu.etaxonomy.cdm.api.service.ITestService;
17 import eu.etaxonomy.cdm.api.service.UpdateResult;
18 import eu.etaxonomy.cdm.api.service.dto.CdmEntityIdentifier;
19 import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
20
21 /**
22 * @author cmathew
23 * @date 26 Jun 2015
24 *
25 */
26 public class RemotingTestUpdateOperation extends RemotingCdmUpdateOperation {
27
28 private static String LABEL = "Test Operation";
29
30 private UpdateResult result;
31 private Exception exception;
32 private CdmEntityIdentifier cei;
33
34
35 /**
36 * @param label
37 * @param action
38 * @param source
39 * @param async
40 */
41 public RemotingTestUpdateOperation(UpdateResult result,
42 Object source,
43 boolean async) {
44 super(LABEL, Action.Update, source, async);
45 this.result = result;
46 }
47
48 public RemotingTestUpdateOperation(Exception exception,
49 Object source,
50 boolean async) {
51 super(LABEL, Action.Update, source, async);
52 this.exception = exception;
53 }
54
55 public RemotingTestUpdateOperation(CdmEntityIdentifier cei,
56 Object source,
57 boolean async) {
58 super(LABEL, Action.Update, source, async);
59 this.cei = cei;
60 }
61
62 /* (non-Javadoc)
63 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
64 */
65 @Override
66 protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
67 ITestService testService = CdmApplicationState.getTestService();
68 if(result != null) {
69 return testService.returnResult(result);
70 } else if(exception != null) {
71 return testService.throwException(exception);
72 } else if(cei != null) {
73 return testService.addChild(cei);
74 }
75 return null;
76 }
77
78 }