Skip to content

Commit

Permalink
Merge pull request #398 from checkmarx-ltd/develop
Browse files Browse the repository at this point in the history
Fixed setting of project level custom fields
  • Loading branch information
satyamchaurasiapersistent authored Apr 16, 2024
2 parents 8463430 + c074404 commit c0cf294
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 66 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.github.checkmarx-ltd</groupId>
<artifactId>cx-spring-boot-sdk</artifactId>
<version>0.6.4</version>
<version>0.6.5</version>


<name>cx-spring-boot-sdk</name>
Expand Down
69 changes: 4 additions & 65 deletions src/main/java/com/checkmarx/sdk/service/CxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ public void updateProjectDetails(CxProject cxProject) throws CheckmarxException
* @return a list of custom fields
* @throws CheckmarxException
*/
public List<CxCustomField> getCustomFields() throws CheckmarxException {
public List<CxCustomField> getAllCustomFields() throws CheckmarxException {
HttpEntity httpEntity = new HttpEntity<>(authClient.createAuthHeaders());
try {
ResponseEntity<CxCustomField[]> projects = restTemplate.exchange(cxProperties.getUrl().concat(CUSTOM_FIELDS), HttpMethod.GET, httpEntity, CxCustomField[].class);
Expand Down Expand Up @@ -2363,14 +2363,13 @@ public Integer createScan(CxScanParams params, String comment) throws CheckmarxE

setProjectExcludeDetails(projectId, params.getFolderExclude(), params.getFileExclude());
if (params.getCustomFields() != null && !params.getCustomFields().isEmpty()) {
List<com.checkmarx.sdk.dto.cx.projectdetails.CustomField> fieldDefinitions = getCustomFieldsFromProjectDetails(projectId);
List<CxCustomField> fieldDefinitions = getAllCustomFields();
List<CxProject.CustomField> customFields = new ArrayList<>();

for (com.checkmarx.sdk.dto.cx.projectdetails.CustomField customFieldObj : fieldDefinitions) {
for (CxCustomField customFieldObj : fieldDefinitions) {
CxProject.CustomField customField = new CxProject.CustomField();
customField.setId(customFieldObj.getId());
customField.setName(customFieldObj.getName());
customField.setValue(customFieldObj.getValue());
customFields.add(customField);
}

Expand All @@ -2387,28 +2386,6 @@ public Integer createScan(CxScanParams params, String comment) throws CheckmarxE
}
}

// for (Map.Entry<String, String> entry : params.getCustomFields().entrySet()) {
// boolean matched = false;
// for (com.checkmarx.sdk.dto.cx.projectdetails.CustomField fieldDefinition : fieldDefinitions) {
// if (fieldDefinition.getName().equalsIgnoreCase(entry.getKey())) {
// matched = true;
// CxProject.CustomField customField = new CxProject.CustomField();
// customField.setId(fieldDefinition.getId());
// customField.setName(fieldDefinition.getName());
// customField.setValue(entry.getValue());
// customFields.add(customField);
// }else{
// CxProject.CustomField customField = new CxProject.CustomField();
// customField.setId(fieldDefinition.getId());
// customField.setName(fieldDefinition.getName());
// customField.setValue(fieldDefinition.getValue());
// customFields.add(customField);
// }
// }
// if (!matched) {
// log.warn("{}: ignoring unrecognised custom field", entry.getKey());
// }
// }
CxProject cxProject = CxProject.builder()
.id(projectId)
.name(params.getProjectName())
Expand All @@ -2421,45 +2398,7 @@ public Integer createScan(CxScanParams params, String comment) throws CheckmarxE
}


//preserving settings
// Gitremotemain gitremotemainObj = getGitRepoDetails(projectId);
// Customremotemain customremotemainObj = getCustomRepoDetails(projectId);
// Perforceremotemain perforceremotemainObj = getPerforceRepoDetails(projectId);
// Sharedremotemain sharedremotemainObj = getSharedRepoDetails(projectId);
// Svnremotemain svnremotemainObj = getSvnRepoDetails(projectId);
// Tfsremotemain tfsremotemainObj = getTfsRepoDetails(projectId);
// ExcludeSettingsmain excludeSettingsmainObj = getExcludeSettingsDetails(projectId);
//Setting Remembered Git Settings
// try {
// if(params.isFileSource() || (params.isGitSource()
// && cxProperties.getEnabledZipScan())){
// if (gitremotemainObj != null) {
// setGitRepoDetails(gitremotemainObj, projectId);
// }
// if (customremotemainObj != null) {
// setCustomRepoDetails(customremotemainObj, projectId);
// }
// if (perforceremotemainObj != null) {
// setPerforceRepoDetails(perforceremotemainObj, projectId);
// }
// if (sharedremotemainObj != null) {
// setSharedRepoDetails(sharedremotemainObj, projectId);
// }
// if (svnremotemainObj != null) {
// setSvnRepoDetails(svnremotemainObj, projectId);
// }
// if (tfsremotemainObj != null) {
// setTfsRepoDetails(tfsremotemainObj, projectId);
// }
//
// if (excludeSettingsmainObj != null) {
// setExcludeSettingsDetails(excludeSettingsmainObj, projectId);
// }
// }
// }catch (Exception e) {
// log.error("Error Occurred While Setting Settings.");
// log.error(ExceptionUtils.getStackTrace(e));
// }

if(params.isIncremental() && projectExistedBeforeScan) {
LocalDateTime scanDate = getLastScanDate(projectId);
if(scanDate == null || LocalDateTime.now().isAfter(scanDate.plusDays(cxProperties.getIncrementalThreshold()))){
Expand Down

0 comments on commit c0cf294

Please sign in to comment.