dea67c830ef0edcc7f7bd940d42ec5cdbd08c83c
[vfc/nfvo/catalog.git] /
1 /**
2  * Copyright 2016 [ZTE] and others.
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
17 package org.openo.commontosca.catalog.filemanage.http;
18
19 import org.openo.commontosca.catalog.filemanage.FileManager;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import java.io.File;
24 import java.io.IOException;
25
26
27 public class HttpFileManagerImpl implements FileManager {
28   private static final Logger LOGGER = LoggerFactory.getLogger(HttpFileManagerImpl.class);
29
30   @Override
31   public boolean upload(String srcPath, String dstPath) {
32     boolean flag = true;
33     LOGGER.info("start upload file.srcPath:" + srcPath + " dstPath" + dstPath);
34     File srcFile = new File(srcPath);
35     if (!srcFile.exists()) {
36       LOGGER.error("src file not exist!");
37       return false;
38     }
39     // File dstFile = new File(ToolUtil.getHttpServerPath() + dstPath);
40     // LOGGER.info("dstFile AbsolutePath:" + dstFile.getAbsolutePath());
41     String targetDir =
42         Class.class.getClass().getResource("/").getPath() + ToolUtil.getHttpServerPath() + dstPath;
43     try {
44       ToolUtil.copyDirectory(srcPath, targetDir, true);
45     } catch (IOException e1) {
46       flag = false;
47       LOGGER.error("copy file failed.errorMsg:" + e1.getMessage());
48     }
49     LOGGER.info("upload file success!");
50     return flag;
51   }
52
53   @Override
54   public boolean download(String srcPath, String dstPath) {
55     // TODO Auto-generated method stub
56     return false;
57   }
58
59   @Override
60   public boolean delete(String srcPath) {
61     boolean flag = true;
62     LOGGER.info("start delete file from http server.srcPath:" + srcPath);
63     flag = ToolUtil.deleteDir(new File(ToolUtil.getHttpServerPath() + srcPath));
64     LOGGER.info("delete file from http server end.flag:" + flag);
65     return flag;
66   }
67
68
69 }