7657e9942581226a500bb9a4fa35dee27884e5ec
[vfc/nfvo/wfengine.git] /
1 /*******************************************************************************
2  * Copyright (c) 2012-2013 University of Stuttgart.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.resources.interfaces;
13
14 import java.util.List;
15
16 import javax.ws.rs.Path;
17
18 import org.eclipse.winery.model.tosca.TInterface;
19 import org.eclipse.winery.model.tosca.TOperation;
20 import org.eclipse.winery.model.tosca.TOperation.InputParameters;
21 import org.eclipse.winery.model.tosca.TOperation.OutputParameters;
22 import org.eclipse.winery.repository.resources._support.IPersistable;
23 import org.eclipse.winery.repository.resources._support.collections.IIdDetermination;
24 import org.eclipse.winery.repository.resources._support.collections.withid.EntityWithIdResource;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class OperationResource extends EntityWithIdResource<TOperation> {
29         
30         private static final Logger logger = LoggerFactory.getLogger(OperationResource.class);
31         
32         
33         public OperationResource(IIdDetermination<TOperation> idDetermination, TOperation o, int idx, List<TOperation> list, IPersistable res) {
34                 super(idDetermination, o, idx, list, res);
35         }
36         
37         /**
38          * @return TOperation object for the corresponding object of operationName
39          *         in the operation list contained in the given interface. null if
40          *         interface could not be found in list
41          */
42         public static TOperation getTOperation(String operationName, TInterface iface) {
43                 List<TOperation> operationList = iface.getOperation();
44                 for (TOperation op : operationList) {
45                         if (op.getName().equals(operationName)) {
46                                 return op;
47                         }
48                 }
49                 return null;
50         }
51         
52         @Path("inputparameters/")
53         public ParametersResource getInputparameters() {
54                 InputParameters inputParameters = this.o.getInputParameters();
55                 if (inputParameters == null) {
56                         inputParameters = new InputParameters();
57                         this.o.setInputParameters(inputParameters);
58                 }
59                 return new ParametersResource(inputParameters.getInputParameter(), this.res);
60         }
61         
62         @Path("outputparameters/")
63         public ParametersResource getOutputparameters() {
64                 OutputParameters outputParameters = this.o.getOutputParameters();
65                 if (outputParameters == null) {
66                         outputParameters = new OutputParameters();
67                         this.o.setOutputParameters(outputParameters);
68                 }
69                 return new ParametersResource(outputParameters.getOutputParameter(), this.res);
70         }
71 }