Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced New Batch Delete API #130

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -177,5 +177,11 @@ public ResponseEntity<List<String>> postQueryAllAssetAdministrationShellIds(Shel
List<String> externalIds = shellService.findExternalShellIdsByIdentifiersByAnyMatch(shellMapper.fromApiDto(assetIds));
return new ResponseEntity<>(externalIds, HttpStatus.OK);
}

@Override
public ResponseEntity<Void> batchDeleteAssetAdministrationShellDescriptor(List<String> aasIdentifierList) {
shellService.deleteAllShell(aasIdentifierList);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public interface ShellRepository extends PagingAndSortingRepository<Shell, UUID>

List<Shell> findShellsByIdExternalIsIn(Set<String> idExternals);

@Query("select s.id from shell s where s.id_external in (:idExternalList)")
Optional<List<UUID>> findMinimalRepresentationListByIdExternalList(List<String> idExternalList);

/**
* Returns external shell ids for the given keyValueCombinations.
* External shell ids matching the conditions below are returned:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
@Service
public class ShellService {

private static final String SHELL_NOT_FOUND = "Shell for identifier %s not found";

private final ShellRepository shellRepository;
private final ShellIdentifierRepository shellIdentifierRepository;
private final SubmodelRepository submodelRepository;
Expand Down Expand Up @@ -77,7 +79,7 @@ public Shell save(Shell shell) {
public Shell findShellByExternalId(String externalShellId) {
return shellRepository.findByIdExternal(externalShellId)
.map(shell -> shell.withIdentifiers(filterSpecificAssetIdsByTenantId(shell.getIdentifiers(), tenantAware.getTenantId())))
.orElseThrow(() -> new EntityNotFoundException(String.format("Shell for identifier %s not found", externalShellId)));
.orElseThrow(() -> new EntityNotFoundException(String.format(SHELL_NOT_FOUND, externalShellId)));
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -206,7 +208,7 @@ private SubmodelMinimal findSubmodelMinimalByExternalId(UUID shellId, String ext

private ShellMinimal findShellMinimalByExternalId(String externalShellId) {
return shellRepository.findMinimalRepresentationByIdExternal(externalShellId)
.orElseThrow(() -> new EntityNotFoundException(String.format("Shell for identifier %s not found", externalShellId)));
.orElseThrow(() -> new EntityNotFoundException(String.format(SHELL_NOT_FOUND, externalShellId)));
}

/**
Expand Down Expand Up @@ -234,4 +236,16 @@ public List<BatchResultDto> saveBatch(List<Shell> shells) {
}).collect(Collectors.toList());
}

@Transactional
public void deleteAllShell(List<String> aasIdentifierList) {
List<UUID> shellListFromDb = findShellMinimalListByExternalIdList(aasIdentifierList);
Iterable<UUID>iterableShellIdList = shellListFromDb;
shellRepository.deleteAllById(iterableShellIdList);
}

private List<UUID> findShellMinimalListByExternalIdList(List<String> externalShellIdList) {
return shellRepository.findMinimalRepresentationListByIdExternalList(externalShellIdList)
.orElseThrow(() -> new EntityNotFoundException(String.format(SHELL_NOT_FOUND, externalShellIdList)));
}

}
25 changes: 25 additions & 0 deletions backend/src/main/resources/static/aas-registry-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,31 @@ paths:
description: Asset Administration Shell Descriptor deleted successfully
x-semanticIds:
- https://admin-shell.io/aas/API/DeleteAssetAdministrationShellDescriptorById/1/0/RC02
/registry/shell-descriptors/batch-delete:
post:
tags:
- Registry and Discovery Interface
summary: Deletes All Asset Administration Shell Descriptor, i.e. de-registers an AAS
operationId: BatchDeleteAssetAdministrationShellDescriptor
requestBody:
description: Delete all shell descriptors for the given identifications.
content:
application/json:
schema:
type: array
minLength: 1
maxItems: 10000
items:
$ref: '#/components/schemas/Identifier'
examples:
complete:
$ref: '#/components/examples/asset-administration-shell-descriptor-fetch-request'
required: true
responses:
"201":
description: Asset Administration Shell Descriptors deleted successfully
x-semanticIds:
- https://admin-shell.io/aas/API/BatchDeleteAssetAdministrationShellDescriptor/1/0/RC02
/registry/shell-descriptors/{aasIdentifier}/submodel-descriptors:
get:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,56 @@ public void testFetchShellsByMultipleIdentificationsExpectSuccessExpectSuccess()
.andExpect(jsonPath("$.items[*].identification",
hasItems(getId(shellPayload1), getId(shellPayload2)) ));
}

@Test
void testDeleteAllShellExpectSuccess() throws Exception {
ObjectNode shellPayload1 = createShell();
performShellCreateRequest(toJson(shellPayload1));

ObjectNode shellPayload2 = createShell();
performShellCreateRequest(toJson(shellPayload2));

ArrayNode fetchTwoShellsById = emptyArrayNode()
.add(getId(shellPayload1))
.add(getId(shellPayload2));

mvc.perform(
MockMvcRequestBuilders
.post(SHELL_BASE_PATH+ "/batch-delete")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content((toJson(fetchTwoShellsById)))
.with(jwtTokenFactory.allRoles())

)
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isNoContent());
}

@Test
void testDeleteAllShellExpectNotFound() throws Exception {
ObjectNode shellPayload1 = createShell();
performShellCreateRequest(toJson(shellPayload1));

ObjectNode shellPayload2 = createShell();
performShellCreateRequest(toJson(shellPayload2));

ArrayNode fetchTwoShellsById = emptyArrayNode()
.add(getId(shellPayload1))
.add(getId(shellPayload2));

mvc.perform(
MockMvcRequestBuilders
.post(SHELL_BASE_PATH+ "/batch-delete")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content((toJson(fetchTwoShellsById)))
.with(jwtTokenFactory.allRoles())

)
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isNoContent());
}
}

}