Code Improvements-Vnfsdk-refrepo sonar issue fixes
[vnfsdk/refrepo.git] / vnfmarket-be / vnf-sdk-marketplace / src / main / java / org / onap / vnfsdk / marketplace / filemanage / http / HttpFileManagerImpl.java
1 /**
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.vnfsdk.marketplace.filemanage.http;
17
18 import java.io.File;
19 import java.io.IOException;
20
21 import org.onap.vnfsdk.marketplace.filemanage.FileManager;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25
26 public class HttpFileManagerImpl implements FileManager {
27   private static final Logger LOGGER = LoggerFactory.getLogger(HttpFileManagerImpl.class);
28
29   @Override
30   public boolean upload(String srcPath, String dstPath) {
31     boolean flag = true;
32     LOGGER.info("start upload file.srcPath:{} dstPath{}" , srcPath , dstPath);
33     File srcFile = new File(srcPath);
34     if (!srcFile.exists()) {
35       LOGGER.error("src file not exist!");
36       return false;
37     }
38
39     String targetDir = ToolUtil.getHttpServerAbsolutePath() + dstPath;
40     try {
41       ToolUtil.copyDirectory(srcPath, targetDir, true);
42     } catch (IOException e1) {
43       flag = false;
44       LOGGER.error("ErrorMsg: failed to copy file:", e1);
45     }
46     LOGGER.info("upload file success!");
47     return flag;
48   }
49
50   @Override
51   public boolean download(String srcPath, String dstPath) {
52     // TODO Auto-generated method stub
53     return false;
54   }
55
56   @Override
57   public boolean delete(String srcPath) {
58     LOGGER.info("start delete file from http server.srcPath:{}" , srcPath);
59     boolean flag = ToolUtil.deleteDir(new File(ToolUtil.getHttpServerAbsolutePath() + srcPath));
60     LOGGER.info("delete file from http server end.flag:{}" , flag);
61     return flag;
62   }
63
64 }
65