Search in sources :

Example 1 with BlackDuckFortifyMapper

use of com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapper in project hub-fortify-ssc-integration-service by blackducksoftware.

the class MappingParser method buildGroupedMappings.

/**
 * This method, groups multiple Hub projects mapped to the same Fortify application.
 *
 * @param blackDuckFortifyMappers
 * @return
 * @throws IOException
 * @throws IntegrationException
 */
private List<BlackDuckFortifyMapperGroup> buildGroupedMappings(List<BlackDuckFortifyMapper> blackDuckFortifyMappers) throws IOException, IntegrationException {
    Map<String, BlackDuckFortifyMapperGroup> mappings = new HashMap<>();
    try {
        for (BlackDuckFortifyMapper blackDuckFortifyMapper : blackDuckFortifyMappers) {
            int applicationId;
            List<HubProjectVersion> hubProjectVersions = new ArrayList<>();
            BlackDuckFortifyMapperGroup blackDuckFortifyMapperGroup;
            HubProjectVersion hubProjectVersion = new HubProjectVersion(blackDuckFortifyMapper.getHubProject(), blackDuckFortifyMapper.getHubProjectVersion());
            String key = blackDuckFortifyMapper.getFortifyApplication() + '_' + blackDuckFortifyMapper.getFortifyApplicationVersion();
            if (mappings.containsKey(key)) {
                blackDuckFortifyMapperGroup = mappings.get(key);
                hubProjectVersions = blackDuckFortifyMapperGroup.getHubProjectVersion();
                applicationId = blackDuckFortifyMapperGroup.getFortifyApplicationId();
            } else {
                applicationId = getFortifyApplicationId(blackDuckFortifyMapper);
            }
            hubProjectVersions.add(hubProjectVersion);
            blackDuckFortifyMapperGroup = new BlackDuckFortifyMapperGroup(blackDuckFortifyMapper.getFortifyApplication(), blackDuckFortifyMapper.getFortifyApplicationVersion(), hubProjectVersions, applicationId);
            mappings.put(key, blackDuckFortifyMapperGroup);
        }
    } catch (IOException ioe) {
        logger.error(ioe.getMessage(), ioe);
        throw new IOException(ioe);
    }
    return new ArrayList<>(mappings.values());
}
Also used : HubProjectVersion(com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion) HashMap(java.util.HashMap) BlackDuckFortifyMapper(com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapper) ArrayList(java.util.ArrayList) BlackDuckFortifyMapperGroup(com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapperGroup) IOException(java.io.IOException) JsonIOException(com.google.gson.JsonIOException)

Example 2 with BlackDuckFortifyMapper

use of com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapper in project hub-fortify-ssc-integration-service by blackducksoftware.

the class MappingParser method createMapping.

/**
 * Creates a list a mappingObject read from the mapping.json file
 *
 * @param filePath
 *            - Filepath to mapping.json
 * @return List<BlackDuckForfifyMapper> Mapped objects with Fortify ID
 * @throws IOException
 * @throws IntegrationException
 */
public List<BlackDuckFortifyMapperGroup> createMapping(String filePath) throws JsonIOException, IOException, IntegrationException {
    Gson gson;
    List<BlackDuckFortifyMapper> mapping;
    try {
        gson = new Gson();
        Type listType = new TypeToken<List<BlackDuckFortifyMapper>>() {
        }.getType();
        mapping = gson.fromJson(new FileReader(filePath), listType);
    } catch (JsonIOException jio) {
        logger.error("Exception occured while creating Mappings", jio);
        throw new JsonIOException("Exception occured while creating Mappings", jio);
    } catch (FileNotFoundException fe) {
        logger.error("File Not Found for creating Mappings", fe);
        throw new FileNotFoundException("Error finding the mapping.json file :: " + filePath);
    }
    return buildGroupedMappings(mapping);
}
Also used : Type(java.lang.reflect.Type) JsonIOException(com.google.gson.JsonIOException) BlackDuckFortifyMapper(com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapper) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader)

Aggregations

BlackDuckFortifyMapper (com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapper)2 JsonIOException (com.google.gson.JsonIOException)2 ArrayList (java.util.ArrayList)2 BlackDuckFortifyMapperGroup (com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapperGroup)1 HubProjectVersion (com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion)1 Gson (com.google.gson.Gson)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 List (java.util.List)1