Search in sources :

Example 1 with UpdateFortifyApplicationAttributesRequest

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

the class MappingParser method addCustomAttributes.

/**
 * Add the custom required attributes to fortify update attribute definition request
 *
 * @param fortifyAttributeDefinition
 * @return
 * @throws IntegrationException
 */
private UpdateFortifyApplicationAttributesRequest addCustomAttributes(FortifyAttributeDefinition fortifyAttributeDefinition) throws IntegrationException {
    List<Value> values = null;
    Object value = null;
    String dataType = fortifyAttributeDefinition.getType();
    try {
        switch(dataType) {
            case "SINGLE":
            case "MULTIPLE":
                values = new ArrayList<>();
                values.addAll(addSingleOrMultipleDataTypeAttributes(fortifyAttributeDefinition));
                break;
            case "TEXT":
            case "LONG_TEXT":
            case "SENSITIVE_TEXT":
                value = attributeConstants.getProperty(fortifyAttributeDefinition.getName().trim());
                break;
            case "INTEGER":
                value = Integer.parseInt(attributeConstants.getProperty(fortifyAttributeDefinition.getName().trim()));
                break;
            case "BOOLEAN":
                value = Boolean.parseBoolean(attributeConstants.getProperty(fortifyAttributeDefinition.getName().trim()));
                break;
            case "DATE":
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                LocalDate.parse(attributeConstants.getProperty(fortifyAttributeDefinition.getName().trim()), formatter);
                value = attributeConstants.getProperty(fortifyAttributeDefinition.getName().trim());
                break;
            default:
                value = attributeConstants.getProperty(fortifyAttributeDefinition.getName().trim());
        }
    } catch (NumberFormatException e) {
        throw new IntegrationException(fortifyAttributeDefinition.getName() + "'s attribute value \"" + attributeConstants.getProperty(fortifyAttributeDefinition.getName().trim()) + "\" is not a valid " + dataType + "!");
    } catch (DateTimeParseException e) {
        throw new IntegrationException(fortifyAttributeDefinition.getName() + "'s attribute value \"" + attributeConstants.getProperty(fortifyAttributeDefinition.getName().trim()) + "\" is not a valid date! Please make sure the date format is yyyy-MM-dd");
    }
    logger.debug("Attribute name::" + fortifyAttributeDefinition.getName() + ", values::" + values + ", value::" + value);
    return new UpdateFortifyApplicationAttributesRequest(fortifyAttributeDefinition.getId(), values, value);
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UpdateFortifyApplicationAttributesRequest(com.blackducksoftware.integration.fortify.model.UpdateFortifyApplicationAttributesRequest) Value(com.blackducksoftware.integration.fortify.model.UpdateFortifyApplicationAttributesRequest.Value) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 2 with UpdateFortifyApplicationAttributesRequest

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

the class MappingParser method addCustomAttributes.

/**
 * Add the custom required attributes to fortify update attribute definition request
 *
 * @param updateAttributerequests
 * @return
 * @throws IOException
 * @throws IntegrationException
 */
public List<UpdateFortifyApplicationAttributesRequest> addCustomAttributes() throws IOException, IntegrationException {
    FortifyAttributeDefinitionResponse fortifyAttributeDefinitionResponse = fortifyAttributeDefinitionApi.getAttributeDefinitions();
    List<String> ignoreAttributes = Arrays.asList("Known Compliance Obligations", "Data Classification", "Application Classification", "Interfaces", "Development Languages", "Authentication System");
    List<UpdateFortifyApplicationAttributesRequest> updateAttributerequests = new ArrayList<>();
    logger.debug(fortifyAttributeDefinitionResponse);
    for (FortifyAttributeDefinition fortifyAttributeDefinition : fortifyAttributeDefinitionResponse.getApplicationAttributeDefinitions()) {
        if (DYNAMIC_SCAN_REQUEST.equalsIgnoreCase(fortifyAttributeDefinition.getCategory())) {
            continue;
        }
        if (Collections.binarySearch(ignoreAttributes, fortifyAttributeDefinition.getName(), String.CASE_INSENSITIVE_ORDER) == 0 && StringUtils.isEmpty(attributeConstants.getProperty(fortifyAttributeDefinition.getName()))) {
            logger.debug("Attribute name::" + fortifyAttributeDefinition.getName() + ", value::" + attributeConstants.getProperty(fortifyAttributeDefinition.getName()));
            updateAttributerequests.add(new UpdateFortifyApplicationAttributesRequest(fortifyAttributeDefinition.getId(), new ArrayList<Value>(), null));
        } else if (StringUtils.isEmpty(attributeConstants.getProperty(fortifyAttributeDefinition.getName()))) {
            throw new IntegrationException("Attribute value for " + fortifyAttributeDefinition.getName() + " is missing in " + propertyConstants.getAttributeFilePath());
        } else {
            updateAttributerequests.add(addCustomAttributes(fortifyAttributeDefinition));
        }
    }
    return updateAttributerequests;
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UpdateFortifyApplicationAttributesRequest(com.blackducksoftware.integration.fortify.model.UpdateFortifyApplicationAttributesRequest) FortifyAttributeDefinition(com.blackducksoftware.integration.fortify.model.FortifyAttributeDefinitionResponse.FortifyAttributeDefinition) ArrayList(java.util.ArrayList) FortifyAttributeDefinitionResponse(com.blackducksoftware.integration.fortify.model.FortifyAttributeDefinitionResponse)

Example 3 with UpdateFortifyApplicationAttributesRequest

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

the class MappingParser method createApplicationVersion.

/**
 * Creates a new Application Version, updates the attributes and commits the application to mark it complete on the
 * UI
 *
 * @param createRequest
 * @return int - Application ID
 * @throws IOException
 * @throws IntegrationException
 */
private int createApplicationVersion(CreateApplicationRequest createRequest) throws IOException, IntegrationException {
    int applicationId = 0;
    applicationId = fortifyApplicationVersionApi.createApplicationVersion(createRequest);
    try {
        final List<UpdateFortifyApplicationAttributesRequest> updateAttributerequest = addCustomAttributes();
        logger.info("updateAttributerequest::" + updateAttributerequest);
        fortifyApplicationVersionApi.updateApplicationAttributes(applicationId, updateAttributerequest);
        CommitFortifyApplicationRequest commitRequest = new CommitFortifyApplicationRequest(true);
        fortifyApplicationVersionApi.commitApplicationVersion(applicationId, commitRequest);
    } catch (IOException e) {
        fortifyApplicationVersionApi.deleteApplicationVersion(applicationId);
        throw new IOException(e);
    } catch (IntegrationException e) {
        fortifyApplicationVersionApi.deleteApplicationVersion(applicationId);
        throw new IntegrationException(e);
    }
    return applicationId;
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UpdateFortifyApplicationAttributesRequest(com.blackducksoftware.integration.fortify.model.UpdateFortifyApplicationAttributesRequest) CommitFortifyApplicationRequest(com.blackducksoftware.integration.fortify.model.CommitFortifyApplicationRequest) IOException(java.io.IOException) JsonIOException(com.google.gson.JsonIOException)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)3 UpdateFortifyApplicationAttributesRequest (com.blackducksoftware.integration.fortify.model.UpdateFortifyApplicationAttributesRequest)3 CommitFortifyApplicationRequest (com.blackducksoftware.integration.fortify.model.CommitFortifyApplicationRequest)1 FortifyAttributeDefinitionResponse (com.blackducksoftware.integration.fortify.model.FortifyAttributeDefinitionResponse)1 FortifyAttributeDefinition (com.blackducksoftware.integration.fortify.model.FortifyAttributeDefinitionResponse.FortifyAttributeDefinition)1 Value (com.blackducksoftware.integration.fortify.model.UpdateFortifyApplicationAttributesRequest.Value)1 JsonIOException (com.google.gson.JsonIOException)1 IOException (java.io.IOException)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 DateTimeParseException (java.time.format.DateTimeParseException)1 ArrayList (java.util.ArrayList)1