package io.lumify.web.clientapi.codegen; import io.lumify.web.clientapi.codegen.ApiException; import io.lumify.web.clientapi.ApiInvoker; import com.sun.jersey.multipart.FormDataMultiPart; import javax.ws.rs.core.MediaType; import java.io.File; import java.util.*; public class AdminApi { protected String basePath = "http://lumify-dev:8889"; protected ApiInvoker apiInvoker = ApiInvoker.getInstance(); public ApiInvoker getInvoker() { return apiInvoker; } public void setBasePath(String basePath) { this.basePath = basePath; } public String getBasePath() { return basePath; } public void uploadOntology (File file) throws ApiException { Object postBody = null; // verify required params are set if(file == null ) { throw new ApiException(400, "missing required params"); } // create path and map variables String path = "/admin/uploadOntology".replaceAll("\\{format\\}","json"); // query params Map<String, String> queryParams = new HashMap<String, String>(); Map<String, String> headerParams = new HashMap<String, String>(); Map<String, String> formParams = new HashMap<String, String>(); String[] contentTypes = { "multipart/form-data"}; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; if(contentType.startsWith("multipart/form-data")) { boolean hasFields = false; FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; com.sun.jersey.core.header.FormDataContentDisposition dispo = com.sun.jersey.core.header.FormDataContentDisposition .name("file") .fileName(file.getName()) .size(file.length()) .build(); com.sun.jersey.multipart.FormDataBodyPart bodyPart = new com.sun.jersey.multipart.FormDataBodyPart(dispo, file, MediaType.MULTIPART_FORM_DATA_TYPE); mp.bodyPart(bodyPart); if(hasFields) postBody = mp; } else { } try { String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); if(response != null){ return ; } else { return ; } } catch (ApiException ex) { if(ex.getCode() == 404) { return ; } else { throw ex; } } } }