com.metaeffekt.mirror.index.advisor.CertEuAdvisorIndex Maven / Gradle / Ivy
/*
* Copyright 2021-2024 the original author or authors.
*
* 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 com.metaeffekt.mirror.index.advisor;
import com.metaeffekt.artifact.analysis.utils.FileUtils;
import com.metaeffekt.mirror.download.documentation.MirrorMetadata;
import com.metaeffekt.mirror.contents.advisory.CertEuAdvisorEntry;
import com.metaeffekt.mirror.download.advisor.CertEuDownload;
import com.metaeffekt.mirror.download.documentation.DocRelevantMethods;
import com.metaeffekt.mirror.index.Index;
import org.apache.lucene.document.Document;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The CERT-EU provides multiple JSON files with one note/advisor per file.
* This process is mostly the same as for all other security advisories.
*/
@MirrorMetadata(directoryName = "certeu-advisors", mavenPropertyName = "certEuAdvisorIndex")
public class CertEuAdvisorIndex extends Index {
private final static Logger LOG = LoggerFactory.getLogger(CertEuAdvisorIndex.class);
public CertEuAdvisorIndex(File baseMirrorDirectory) {
super(baseMirrorDirectory, CertEuAdvisorIndex.class, Collections.singletonList(CertEuDownload.class), Collections.emptyList());
}
@Override
@DocRelevantMethods({"CertEuAdvisorEntry#fromDownloadJson"})
protected Map createIndexDocuments() {
final Map documents = new HashMap<>();
final List files = super.getAllFilesInSubDirectories(new File(super.requiredDownloads[0], "publications"));
LOG.info("Found [{}] CERT-EU advisory files", files.size());
for (File file : files) {
try {
final List contents = FileUtils.readLines(file, StandardCharsets.UTF_8);
final JSONObject jsonContent = new JSONObject(String.join("", contents));
final CertEuAdvisorEntry parsedEntry = CertEuAdvisorEntry.fromDownloadJson(jsonContent);
documents.put(parsedEntry.getId(), parsedEntry.toDocument());
} catch (IOException e) {
throw new RuntimeException("Unable to read file contents during indexing ", e);
}
}
return documents;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy