RED-8762: added endpoint to update flag addToDictionary for given type, dossierTemplateId and dossierId

This commit is contained in:
Ali Oezyetimoglu 2024-04-11 14:32:39 +02:00
parent f870759747
commit 623068e1a1
4 changed files with 44 additions and 5 deletions

View File

@ -22,12 +22,10 @@ import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.iqser.red.service.persistence.management.v1.processor.service.AccessControlService;
import com.knecon.fforesight.keycloakcommons.security.KeycloakSecurity;
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
import com.iqser.red.service.persistence.management.v1.processor.service.AccessControlService;
import com.iqser.red.service.persistence.management.v1.processor.service.DictionaryService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.AuditPersistenceService;
import com.knecon.fforesight.databasetenantcommons.providers.utils.MagicConverter;
import com.iqser.red.service.persistence.management.v1.processor.utils.StringEncodingUtils;
import com.iqser.red.service.persistence.management.v1.processor.utils.TypeValueMapper;
import com.iqser.red.service.persistence.service.v1.api.external.resource.DictionaryResource;
@ -41,6 +39,8 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.audit.Audit
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.configuration.Colors;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntryType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.Type;
import com.knecon.fforesight.databasetenantcommons.providers.utils.MagicConverter;
import com.knecon.fforesight.keycloakcommons.security.KeycloakSecurity;
import feign.FeignException;
import jakarta.validation.Valid;
@ -322,4 +322,14 @@ public class DictionaryController implements DictionaryResource {
.build());
}
@Override
public void changeFlags(@PathVariable(TYPE_PARAMETER_NAME) String type,
@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId,
@RequestParam(value = DOSSIER_ID_PARAMETER_NAME) String dossierId,
@RequestParam(value = "addToDictionary") boolean addToDictionary) {
dictionaryService.changeAddToDictionary(type, dossierTemplateId, dossierId, addToDictionary);
}
}

View File

@ -51,6 +51,8 @@ public interface DictionaryResource {
String MERGED = "/merged";
String DELETE = "/delete";
String UPDATE_FLAG = "/updateFlag";
String COLOR_REST_PATH = ExternalApi.BASE_PATH + "/color";
String DOSSIER_ID_PARAMETER_NAME = "dossierId";
@ -196,4 +198,14 @@ public interface DictionaryResource {
@GetMapping(value = COLOR_REST_PATH + DOSSIER_TEMPLATE_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
Colors getColors(@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId);
}
@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping(value = DICTIONARY_REST_PATH + UPDATE_FLAG + TYPE_PATH_VARIABLE + DOSSIER_TEMPLATE_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Updates flags regarding to selected type, dossier and dossier template.", description = "None")
@ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Successfully updated the flags of the type."), @ApiResponse(responseCode = "400", description = "Request contains error."), @ApiResponse(responseCode = "404", description = "The entry type is not found.")})
void changeFlags(@PathVariable(TYPE_PARAMETER_NAME) String type,
@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId,
@RequestParam(value = DOSSIER_ID_PARAMETER_NAME) String dossierId,
@RequestParam(value = "addToDictionary") boolean addToDictionary);
}

View File

@ -227,7 +227,7 @@ public class DictionaryService {
accessControlService.verifyUserHasViewPermissions(dossierId);
dictionaryManagementService.checkDossierMatchesDossierTemplate(dossierId, dossierTemplateId);
// for every dossier template type check if a dossier type exists
types.forEach(t -> dictionaryManagementService.checkForDossierTypeExistenceAndCreate(toTypeId(t.getType(), t.getDossierTemplateId(), dossierId),includeDeleted));
types.forEach(t -> dictionaryManagementService.checkForDossierTypeExistenceAndCreate(toTypeId(t.getType(), t.getDossierTemplateId(), dossierId), includeDeleted));
types.addAll(MagicConverter.convert(dictionaryPersistenceService.getAllTypesForDossier(dossierId, includeDeleted), Type.class));
} catch (AccessDeniedException e) {
log.debug(" Don't include the types for the dossier id");
@ -431,4 +431,15 @@ public class DictionaryService {
return MagicConverter.convert(colorsService.getColors(dossierTemplateId), Colors.class);
}
public void changeAddToDictionary(String type, String dossierTemplateId, String dossierId, boolean addToDictionary) {
var typeEntity = dictionaryPersistenceService.getType(toTypeId(type, dossierTemplateId, dossierId));
if (typeEntity.isDossierDictionaryOnly()) {
typeEntity.setAddToDictionaryAction(addToDictionary);
dictionaryPersistenceService.saveType(typeEntity);
}
}
}

View File

@ -279,6 +279,12 @@ public class DictionaryPersistenceService {
}
public void saveType(TypeEntity type) {
typeRepository.saveAndFlush(type);
}
@Transactional
public int undeleteType(String typeId) {