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);
}
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;
}
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;
}
Aggregations