/*
 * Copyright 2015-2020 OpenCB
 *
 * 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 org.opencb.cellbase.lib.download;

import org.apache.commons.lang.StringUtils;
import org.opencb.cellbase.core.config.CellBaseConfiguration;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.lib.EtlCommons;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PubMedDownloadManager extends AbstractDownloadManager {

    private static final String PUBMED_NAME = "PUBMED";
    public PubMedDownloadManager(String species, String assembly, Path targetDirectory, CellBaseConfiguration configuration)
            throws IOException, CellBaseException {
        super(species, assembly, targetDirectory, configuration);
    }

    @Override
    public List<DownloadFile> download() throws IOException, InterruptedException {
        logger.info("Downloading PubMed XML files...");

        Path pubmedFolder = downloadFolder.resolve("pubmed");
        Files.createDirectories(pubmedFolder);

        // Downloads PubMed XML files
        String url = configuration.getDownload().getPubmed().getHost();
        String regexp = configuration.getDownload().getPubmed().getFiles().get(0);
        String[] name = regexp.split("[\\[\\]]");
        System.out.println(StringUtils.join(name, " ---- "));
        String[] split = name[1].split("\\.\\.");
        System.out.println(StringUtils.join(split, " ---- "));
        int start = Integer.valueOf(split[0]);
        int end = Integer.valueOf(split[1]);
        int padding = Integer.valueOf(split[2]);

        saveVersionData(EtlCommons.PUBMED_DATA, PUBMED_NAME, null, getTimeStamp(), Collections.singletonList(url),
                pubmedFolder.resolve("pubmedVersion.json"));

        List<DownloadFile> list = new ArrayList<>();
        for (int i = start; i <= end; i++) {
            String filename = name[0] + String.format("%0" + padding + "d", i) + name[2];
            list.add(downloadFile(url + "/" + filename, pubmedFolder.resolve(filename).toString()));
        }
        return list;
    }
}

@@ -636,52 +636,8 @@
 d;%0A%0A
-import org.apache.commons.lang.StringUtils;%0A
 impo
@@ -1861,171 +1861,46 @@
    S
-ystem.out.println(StringUtils.join(name, %22 ---- %22));%0A        String%5B%5D split = name%5B1%5D.split(%22%5C%5C.%5C%5C.%22);%0A        System.out.println(StringUtils.join(split, %22 ---- %22)
+tring%5B%5D split = name%5B1%5D.split(%22%5C%5C.%5C%5C.%22
 );%0A 
@@ -2405,16 +2405,75 @@
 ame%5B2%5D;%0A
+            logger.info(%22%5CtDownloading file %22 + filename);%0A
         

improve log info when downloading PubMed files, #TASK-891