Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ void updateType(@Param("assetIds") List<Long> assetIds,
void updateGroup(@Param("assetIds") List<Long> assetIds,
@Param("assetGroupId") Long assetGroupId);

@Modifying
@Query("UPDATE UtmNetworkScan s SET s.assetNotes = :assetNotes WHERE s.id IN :assetIds")
void updateNotes(@Param("assetIds") List<Long> assetIds,
@Param("assetNotes") String assetNotes);

@Modifying
@Query("UPDATE UtmNetworkScan s SET s.assetAlias = :assetAlias WHERE s.id IN :assetIds")
void updateAlias(@Param("assetIds") List<Long> assetIds,
@Param("assetAlias") String assetAlias);

Optional<List<UtmNetworkScan>> findAllByAssetStatus(AssetStatus status);

Optional<List<UtmNetworkScan>> findAllByServerNameAndRegisteredMode(String serverName, AssetRegisteredMode registeredMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,35 @@ public void updateGroup(List<Long> assetIds, Long assetGroupId) throws Exception
}
}

/**
* Update ONLY the notes of the given assets. Unlike the whole-entity
* save() used by PUT /utm-network-scans, this cannot clobber other
* columns (group_id, asset_type_id, ...) when the caller sends a list
* row that lacks them (#2967).
*/
public void updateNotes(List<Long> assetIds, String assetNotes) throws Exception {
final String ctx = CLASSNAME + ".updateNotes";
Assert.notEmpty(assetIds, ctx + ": Missing parameter [assetIds]");
try {
networkScanRepository.updateNotes(assetIds, assetNotes);
} catch (Exception e) {
throw new Exception(ctx + ": " + e.getMessage());
}
}

/**
* Update ONLY the alias of the given assets (same rationale as updateNotes).
*/
public void updateAlias(List<Long> assetIds, String assetAlias) throws Exception {
final String ctx = CLASSNAME + ".updateAlias";
Assert.notEmpty(assetIds, ctx + ": Missing parameter [assetIds]");
try {
networkScanRepository.updateAlias(assetIds, assetAlias);
} catch (Exception e) {
throw new Exception(ctx + ": " + e.getMessage());
}
}

/**
* Find all network scan results without paginating them
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,44 @@ public ResponseEntity<Void> updateGroup(@Valid @RequestBody UpdateGroupRequestBo
}
}

/**
* PUT /utm-network-scans/updateNotes : updates ONLY the note text of the
* given assets. The note/alias row actions used to send the whole list row
* (a NetworkScanDTO) to the entity PUT, which nulls group_id/asset_type_id
* because the DTO carries those only as read-only relations (#2967). This
* field-scoped endpoint avoids that. Mirrors updateGroup/updateType (no
* existence guard: a missing id is a no-op, as there).
*/
@PutMapping("/utm-network-scans/updateNotes")
public ResponseEntity<Void> updateNotes(@Valid @RequestBody UpdateFieldRequestBody body) {
final String ctx = CLASSNAME + ".updateNotes";
try {
networkScanService.updateNotes(body.getAssetsIds(), body.getValue());
return ResponseEntity.ok().build();
} catch (Exception e) {
String msg = ctx + ": " + e.getMessage();
log.error(msg);
eventService.createEvent(msg, ApplicationEventType.ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(
HeaderUtil.createFailureAlert("", "", msg)).body(null);
}
}

@PutMapping("/utm-network-scans/updateAlias")
public ResponseEntity<Void> updateAlias(@Valid @RequestBody UpdateFieldRequestBody body) {
final String ctx = CLASSNAME + ".updateAlias";
try {
networkScanService.updateAlias(body.getAssetsIds(), body.getValue());
return ResponseEntity.ok().build();
} catch (Exception e) {
String msg = ctx + ": " + e.getMessage();
log.error(msg);
eventService.createEvent(msg, ApplicationEventType.ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(
HeaderUtil.createFailureAlert("", "", msg)).body(null);
}
}

/**
* GET /utm-network-scans : get all the utmNetworkScans.
*
Expand Down Expand Up @@ -333,4 +371,27 @@ public void setAssetGroupId(Long assetGroupId) {
this.assetGroupId = assetGroupId;
}
}

public static class UpdateFieldRequestBody {
@NotEmpty
private List<Long> assetsIds;

private String value;

public List<Long> getAssetsIds() {
return assetsIds;
}

public void setAssetsIds(List<Long> assetsIds) {
this.assetsIds = assetsIds;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class AssetEditAliasComponent implements OnInit {

editAlias() {
this.creating = true;
this.utmNetScanService.update(this.asset)
// Dedicated alias endpoint: the whole-entity update() would NULL out
// group_id/asset_type_id because the list row does not carry them (#2967).
this.utmNetScanService.updateAlias({value: this.asset.assetAlias, assetsIds: [this.asset.id]})
.subscribe(response => {
this.utmToastService.showSuccessBottom('Asset alias created successfully');
this.assetReloadFilterBehavior.$assetReloadFilter.next(AssetFieldFilterEnum.ALIAS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ export class AssetsApplyNoteComponent implements OnInit {

addNote() {
this.creating = true;
const asset = {
...this.asset,
metrics: []
};
this.utmNetScanService.update(asset).subscribe(response => {
// Dedicated note endpoint: the whole-entity update() below would persist
// the list row as the entity and NULL out group_id/asset_type_id, which
// the row (NetworkScanDTO) does not carry (#2967).
this.utmNetScanService.updateNotes({value: this.asset.assetNotes, assetsIds: [this.asset.id]}).subscribe(response => {
this.utmToastService.showSuccessBottom('Comment added successfully');
this.applyNote.emit('success');
this.focus.emit(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ export class UtmNetScanService extends RefreshDataService<boolean, HttpResponse<
return this.http.put<any>(this.resourceUrl + '/updateGroup', asset, {observe: 'response'});
}

// Dedicated single-field updates: they must not reuse the whole-entity
// update() above, which persists missing columns as NULL (e.g. group_id,
// asset_type_id) when fed a list row (#2967).
updateNotes(asset: { value: string, assetsIds: number[] }): Observable<HttpResponse<any>> {
return this.http.put<any>(this.resourceUrl + '/updateNotes', asset, {observe: 'response'});
}

updateAlias(asset: { value: string, assetsIds: number[] }): Observable<HttpResponse<any>> {
return this.http.put<any>(this.resourceUrl + '/updateAlias', asset, {observe: 'response'});
}

deleteCustomAsset(id: number): Observable<HttpResponse<any>> {
return this.http.delete<any>(this.resourceUrl + '/deleteCustomAsset/' + id, {observe: 'response'});
}
Expand Down
Loading