* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.pdp.rest.api.services;
import java.io.BufferedInputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
importResponse = XACMLErrorConstants.ERROR_DATA_ISSUE + e;
status = HttpStatus.BAD_REQUEST;
}
+
+ // Save the imported file
+ if (!file.isEmpty() && status.equals(HttpStatus.OK) ) {
+ String filePath = null;
+ try {
+ String uploadsDir = System.getProperty("msToscaModel.home");
+ if(uploadsDir != null) {
+ if(! new File(uploadsDir).exists()){
+ new File(uploadsDir).mkdir();
+ }
+ String orgName = file.getOriginalFilename();
+ filePath = uploadsDir + orgName;
+ File dest = new File(filePath);
+ file.transferTo(dest);
+ }
+ }catch(Exception e){
+ LOGGER.error("Operation: policyEngineImport : " + e.getMessage() + ". " + filePath + " is not a valid file path.");
+ }
+ }
}
private void specialCheck() {
String fileName = file.getOriginalFilename();
switch (importParameters.getServiceType()){
case MICROSERVICE:
- if (fileName.endsWith(".xmi") || fileName.endsWith(".zip")){
+ case OPTIMIZATION:
+ if (fileName.endsWith(".yml") || fileName.endsWith(".xmi") || fileName.endsWith(".zip")){
try {
targetStream = new BufferedInputStream(file.getInputStream());
} catch (IOException e) {
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing service Type value.";
return false;
}
- if(importParameters.getServiceType().equals(IMPORT_TYPE.MICROSERVICE) && (importParameters.getVersion()==null || importParameters.getVersion().trim().isEmpty())){
+ if((IMPORT_TYPE.MICROSERVICE.equals(importParameters.getServiceType()) || IMPORT_TYPE.OPTIMIZATION.equals(importParameters.getServiceType()))
+ && (importParameters.getVersion()==null || importParameters.getVersion().trim().isEmpty())){
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing version value.";
return false;
}