fixed elastic search update issue when entity is restored (#11488)

Co-authored-by: Himank Mehta <himankmehta@Himanks-MacBook-Air.local>
Co-authored-by: Mohit Yadav <105265192+mohityadav766@users.noreply.github.com>
This commit is contained in:
07Himank 2023-05-08 23:52:41 +05:30 committed by GitHub
parent 98201724c3
commit 196681b499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -1047,7 +1047,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
return RestUtil.getHref(uriInfo, collectionPath, id);
}
public T restoreEntity(String updatedBy, String entityType, UUID id) throws IOException {
public PutResponse<T> restoreEntity(String updatedBy, String entityType, UUID id) throws IOException {
// If an entity being restored contains other **deleted** children entities, restore them
List<EntityRelationshipRecord> records =
daoCollection.relationshipDAO().findTo(id.toString(), entityType, Relationship.CONTAINS.ordinal());
@ -1062,10 +1062,15 @@ public abstract class EntityRepository<T extends EntityInterface> {
// Finally set entity deleted flag to false
LOG.info("Restoring the {} {}", entityType, id);
T entity = dao.findEntityById(id, DELETED);
entity.setDeleted(false);
dao.update(entity.getId(), JsonUtils.pojoToJson(entity));
return entity;
T original = dao.findEntityById(id, DELETED);
setFieldsInternal(original, putFields);
T updated = JsonUtils.readValue(JsonUtils.pojoToJson(original), entityClass);
updated.setUpdatedBy(updatedBy);
updated.setUpdatedAt(System.currentTimeMillis());
EntityUpdater updater = getUpdater(original, updated, Operation.PUT);
updater.update();
String change = updater.fieldsChanged() ? RestUtil.ENTITY_UPDATED : RestUtil.ENTITY_NO_CHANGE;
return new PutResponse<>(Status.OK, updated, change);
}
public void addRelationship(UUID fromId, UUID toId, String fromEntity, String toEntity, Relationship relationship) {

View File

@ -249,9 +249,10 @@ public abstract class EntityResource<T extends EntityInterface, K extends Entity
public Response restoreEntity(UriInfo uriInfo, SecurityContext securityContext, UUID id) throws IOException {
OperationContext operationContext = new OperationContext(entityType, MetadataOperation.EDIT_ALL);
authorizer.authorize(securityContext, operationContext, getResourceContextById(id));
T entity = addHref(uriInfo, dao.restoreEntity(securityContext.getUserPrincipal().getName(), entityType, id));
LOG.info("Restored {}:{}", Entity.getEntityTypeFromObject(entity), entity.getId());
return Response.ok(entity.getHref()).entity(entity).build();
PutResponse<T> response = dao.restoreEntity(securityContext.getUserPrincipal().getName(), entityType, id);
addHref(uriInfo, response.getEntity());
LOG.info("Restored {}:{}", Entity.getEntityTypeFromObject(response.getEntity()), response.getEntity().getId());
return response.toResponse();
}
public String exportCsvInternal(SecurityContext securityContext, String name) throws IOException {