Commit e1e33d95 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Make parameter more generic

parent a5bb42ce
...@@ -15,10 +15,8 @@ ...@@ -15,10 +15,8 @@
*/ */
package nl.uva.sne.drip.api.rest; package nl.uva.sne.drip.api.rest;
import nl.uva.sne.drip.commons.types.FileParameter; import nl.uva.sne.drip.commons.types.Parameter;
import com.fasterxml.jackson.databind.ObjectMapper;
import nl.uva.sne.drip.api.rpc.PlannerCaller; import nl.uva.sne.drip.api.rpc.PlannerCaller;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -28,6 +26,7 @@ import java.util.List; ...@@ -28,6 +26,7 @@ import java.util.List;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.uva.sne.drip.commons.types.IParameter;
import nl.uva.sne.drip.commons.types.Message; import nl.uva.sne.drip.commons.types.Message;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -37,7 +36,6 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -37,7 +36,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import nl.uva.sne.drip.commons.types.IMessage;
/** /**
* *
...@@ -69,7 +67,7 @@ public class UploadToscaController { ...@@ -69,7 +67,7 @@ public class UploadToscaController {
Message invokationMessage = new Message(); Message invokationMessage = new Message();
List parameters = new ArrayList(); List parameters = new ArrayList();
FileParameter fileArgument = new FileParameter(); Parameter fileArgument = new Parameter();
byte[] bytes = file.getBytes();//Files.readAllBytes(Paths.get(targetToscaFile.getAbsolutePath())); byte[] bytes = file.getBytes();//Files.readAllBytes(Paths.get(targetToscaFile.getAbsolutePath()));
String charset = "UTF-8"; String charset = "UTF-8";
fileArgument.setValue(new String(bytes, charset)); fileArgument.setValue(new String(bytes, charset));
...@@ -77,7 +75,7 @@ public class UploadToscaController { ...@@ -77,7 +75,7 @@ public class UploadToscaController {
fileArgument.setName(name); fileArgument.setName(name);
parameters.add(fileArgument); parameters.add(fileArgument);
fileArgument = new FileParameter(); fileArgument = new Parameter();
bytes = Files.readAllBytes(Paths.get("/home/alogo/Downloads/DRIP/example_a.yml")); bytes = Files.readAllBytes(Paths.get("/home/alogo/Downloads/DRIP/example_a.yml"));
fileArgument.setValue(new String(bytes, charset)); fileArgument.setValue(new String(bytes, charset));
fileArgument.setEncoding(charset); fileArgument.setEncoding(charset);
...@@ -103,16 +101,26 @@ public class UploadToscaController { ...@@ -103,16 +101,26 @@ public class UploadToscaController {
public Message args() { public Message args() {
try { try {
Message r = new Message(); Message r = new Message();
List args = new ArrayList(); List<IParameter> args = new ArrayList();
args.add(1); IParameter intParam = new Parameter();
args.add("str"); intParam.setValue("1");
FileParameter targetToscaFile = new FileParameter(); args.add(intParam);
Parameter strParam = new Parameter();
strParam.setValue("string");
args.add(strParam);
IParameter targetToscaFile = new Parameter();
byte[] bytes = Files.readAllBytes(Paths.get("/home/alogo/Downloads/planner_output_all.yml")); byte[] bytes = Files.readAllBytes(Paths.get("/home/alogo/Downloads/planner_output_all.yml"));
targetToscaFile.setValue(new String(bytes, "UTF-8")); targetToscaFile.setValue(new String(bytes, "UTF-8"));
targetToscaFile.setName("planner_output_all.yml"); targetToscaFile.setName("planner_output_all.yml");
targetToscaFile.setEncoding("UTF-8"); targetToscaFile.setEncoding("UTF-8");
args.add(targetToscaFile); args.add(targetToscaFile);
IParameter file = new Parameter();
file.setName("Dockerfile");
file.setURL("https://github.com/QCAPI-DRIP/DRIP-integradation/releases/download/valpha/Dockerfile");
args.add(file);
r.setParameters(args); r.setParameters(args);
r.setCreationDate(new Date(System.currentTimeMillis())); r.setCreationDate(new Date(System.currentTimeMillis()));
......
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.commons.types;
/**
*
* @author S. Koulouzis.
*/
public interface IFileParameter {
public String getURL();
public void setURL(String url);
public String getEncoding();
public void setEncoding(String encoding);
public void setName(String name);
public String getName();
}
...@@ -28,8 +28,8 @@ public interface IMessage { ...@@ -28,8 +28,8 @@ public interface IMessage {
public void setCreationDate(Date creationDate); public void setCreationDate(Date creationDate);
public void setParameters(List args); public void setParameters(List<IParameter> params);
public List getParameters(); public List getParameters();
} }
...@@ -21,6 +21,11 @@ package nl.uva.sne.drip.commons.types; ...@@ -21,6 +21,11 @@ package nl.uva.sne.drip.commons.types;
*/ */
public interface IParameter { public interface IParameter {
public static final String NAME = "name";
public static final String URL = "url";
public static final String VALUE = "value";
public static final String ENCODING = "encoding";
public void setName(String name); public void setName(String name);
public String getName(); public String getName();
...@@ -29,4 +34,12 @@ public interface IParameter { ...@@ -29,4 +34,12 @@ public interface IParameter {
public void setValue(String value); public void setValue(String value);
public String getURL();
public void setURL(String url);
public String getEncoding();
public void setEncoding(String encoding);
} }
...@@ -49,7 +49,7 @@ public class Message implements IMessage, Serializable { ...@@ -49,7 +49,7 @@ public class Message implements IMessage, Serializable {
} }
@Override @Override
public void setParameters(List args) { public void setParameters(List<IParameter> args) {
this.parameters = args; this.parameters = args;
} }
......
...@@ -21,12 +21,7 @@ import java.io.Serializable; ...@@ -21,12 +21,7 @@ import java.io.Serializable;
* *
* @author S. Koulouzis. * @author S. Koulouzis.
*/ */
public class FileParameter implements IFileParameter, IParameter, Serializable { public class Parameter implements IParameter, Serializable {
public static final String NAME = "name";
public static final String URL = "url";
public static final String VALUE = "value";
public static final String ENCODING = "encoding";
private String url; private String url;
private String encoding; private String encoding;
......
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.commons.types;
/**
*
* @author S. Koulouzis
*/
import java.util.List;
//import org.springframework.data.repository.PagingAndSortingRepository;
//import org.springframework.data.repository.query.Param;
//import org.springframework.data.rest.core.annotation.RepositoryRestResource;
//@RepositoryRestResource(collectionResourceRel = "requests", path = "requests")
public interface RequestRepository {//extends PagingAndSortingRepository<Request, Long> {
// List<Request> findById(@Param("id") String id);
}
...@@ -32,15 +32,13 @@ import java.util.Date; ...@@ -32,15 +32,13 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.uva.sne.drip.commons.types.FileParameter; import nl.uva.sne.drip.commons.types.Parameter;
import nl.uva.sne.drip.commons.types.Message; import nl.uva.sne.drip.commons.types.Message;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import nl.uva.sne.drip.commons.types.IFileParameter;
/** /**
* *
...@@ -95,15 +93,15 @@ public class Consumer extends DefaultConsumer { ...@@ -95,15 +93,15 @@ public class Consumer extends DefaultConsumer {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Map<String, String> fileArg = (java.util.LinkedHashMap) request.getParameters().get(i); Map<String, String> fileArg = (java.util.LinkedHashMap) request.getParameters().get(i);
String fileName = fileArg.get(FileParameter.NAME); String fileName = fileArg.get(Parameter.NAME);
//If not null should be able to use it to download file //If not null should be able to use it to download file
String url = fileArg.get(FileParameter.URL); String url = fileArg.get(Parameter.URL);
if (url != null) { if (url != null) {
//download //download
} }
String encoding = fileArg.get(FileParameter.ENCODING); String encoding = fileArg.get(Parameter.ENCODING);
String value = fileArg.get(FileParameter.VALUE); String value = fileArg.get(Parameter.VALUE);
try (PrintWriter out = new PrintWriter(fileName)) { try (PrintWriter out = new PrintWriter(fileName)) {
out.print(value); out.print(value);
} }
...@@ -120,7 +118,7 @@ public class Consumer extends DefaultConsumer { ...@@ -120,7 +118,7 @@ public class Consumer extends DefaultConsumer {
//We know that in parameters 0-2 we should have files //We know that in parameters 0-2 we should have files
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
JSONObject arg = (JSONObject) args.get(i); JSONObject arg = (JSONObject) args.get(i);
String fileName = (String) arg.get(FileParameter.NAME); String fileName = (String) arg.get(Parameter.NAME);
//If not null should be able to use it to download file //If not null should be able to use it to download file
if (!arg.isNull("url")) { if (!arg.isNull("url")) {
...@@ -128,8 +126,8 @@ public class Consumer extends DefaultConsumer { ...@@ -128,8 +126,8 @@ public class Consumer extends DefaultConsumer {
//download //download
} }
//Otherwise get contents as string //Otherwise get contents as string
String value = (String) arg.get(FileParameter.VALUE); String value = (String) arg.get(Parameter.VALUE);
String encoding = (String) arg.get(FileParameter.ENCODING); String encoding = (String) arg.get(Parameter.ENCODING);
try (PrintWriter out = new PrintWriter(fileName)) { try (PrintWriter out = new PrintWriter(fileName)) {
out.print(value); out.print(value);
...@@ -145,7 +143,7 @@ public class Consumer extends DefaultConsumer { ...@@ -145,7 +143,7 @@ public class Consumer extends DefaultConsumer {
List parameters = new ArrayList(); List parameters = new ArrayList();
String charset = "UTF-8"; String charset = "UTF-8";
for (File f : files) { for (File f : files) {
FileParameter fileParam = new FileParameter(); Parameter fileParam = new Parameter();
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath())); byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
fileParam.setValue(new String(bytes, charset)); fileParam.setValue(new String(bytes, charset));
fileParam.setEncoding(charset); fileParam.setEncoding(charset);
......
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