use of nikita.common.model.noark5.v4.admin.AdministrativeUnit in project nikita-noark5-core by HiOA-ABI.
the class AdministrativeUnitService method update.
/**
* update a particular administrativeUnit. <br>
*
* @param incomingAdministrativeUnit
* @return the updated administrativeUnit
*/
@Override
public AdministrativeUnit update(String systemId, Long version, AdministrativeUnit incomingAdministrativeUnit) {
AdministrativeUnit existingAdministrativeUnit = getAdministrativeUnitOrThrow(systemId);
// Here copy all the values you are allowed to copy ....
if (null != existingAdministrativeUnit.getAdministrativeUnitName()) {
existingAdministrativeUnit.setAdministrativeUnitName(incomingAdministrativeUnit.getAdministrativeUnitName());
}
if (null != existingAdministrativeUnit.getShortName()) {
existingAdministrativeUnit.setShortName(incomingAdministrativeUnit.getShortName());
}
existingAdministrativeUnit.setVersion(version);
administrativeUnitRepository.save(existingAdministrativeUnit);
return administrativeUnitRepository.save(incomingAdministrativeUnit);
}
use of nikita.common.model.noark5.v4.admin.AdministrativeUnit in project nikita-noark5-core by HiOA-ABI.
the class AdministrativeUnitService method getAdministrativeUnitOrThrow.
// All HELPER operations
/**
* Internal helper method. Rather than having a find and try catch in multiple methods, we have it here once.
* If you call this, be aware that you will only ever get a valid AdministrativeUnit back. If there is no valid
* AdministrativeUnit, an exception is thrown
*
* @param administrativeUnitSystemId
* @return
*/
protected AdministrativeUnit getAdministrativeUnitOrThrow(@NotNull String administrativeUnitSystemId) {
AdministrativeUnit administrativeUnit = administrativeUnitRepository.findBySystemIdOrderBySystemId(administrativeUnitSystemId);
if (administrativeUnit == null) {
String info = INFO_CANNOT_FIND_OBJECT + " AdministrativeUnit, using systemId " + administrativeUnitSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
}
return administrativeUnit;
}
use of nikita.common.model.noark5.v4.admin.AdministrativeUnit in project nikita-noark5-core by HiOA-ABI.
the class AdministrativeUnitController method findBySystemIdOrderBySystemId.
// Retrieves a given administrativeUnit identified by a systemId
// GET [contextPath][api]/admin/administrativtenhet/{systemId}/
@ApiOperation(value = "Gets administrativeUnit identified by its systemId", notes = "Returns the requested " + " administrativeUnit object", response = AdministrativeUnit.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "AdministrativeUnit " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = AdministrativeUnit.class), @ApiResponse(code = 201, message = "AdministrativeUnit " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = AdministrativeUnit.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_MALFORMED_PAYLOAD), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR), @ApiResponse(code = 501, message = API_MESSAGE_NOT_IMPLEMENTED) })
@Counted
@Timed
@RequestMapping(value = ADMINISTRATIVE_UNIT + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH, method = RequestMethod.GET)
public ResponseEntity<AdministrativeUnitHateoas> findBySystemIdOrderBySystemId(@PathVariable("systemID") final String systemId, HttpServletRequest request) {
AdministrativeUnit administrativeUnit = administrativeUnitService.findBySystemIdOrderBySystemId(systemId);
AdministrativeUnitHateoas adminHateoas = new AdministrativeUnitHateoas(administrativeUnit);
administrativeUnitHateoasHandler.addLinks(adminHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(administrativeUnit.getVersion().toString()).body(adminHateoas);
}
use of nikita.common.model.noark5.v4.admin.AdministrativeUnit in project nikita-noark5-core by HiOA-ABI.
the class RegistryEntryHateoasController method getCorrespondencePartInternalTemplate.
// Create a suggested CorrespondencePartInternal (like a template) object with default values (nothing persisted)
// GET [contextPath][api]/casehandling/journalpost/{systemId}/ny-korrespondansepartintern
@ApiOperation(value = "Suggests the contents of a new CorrespondencePartInternal object", notes = "Returns a pre-filled CorrespondencePartInternal object" + " with values relevant for the logged-in user", response = CorrespondencePartInternalHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "CorrespondencePart " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = CorrespondencePartInternalHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.GET, value = { SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_CORRESPONDENCE_PART_INTERNAL })
public ResponseEntity<String> getCorrespondencePartInternalTemplate(HttpServletRequest request) throws NikitaException {
CorrespondencePartInternal suggestedCorrespondencePart = new CorrespondencePartInternal();
CorrespondencePartType correspondencePartType = correspondencePartTypeService.findByCode(CORRESPONDENCE_PART_CODE_EA);
if (correspondencePartType == null) {
throw new NikitaException("Internal error, metadata missing. [" + CORRESPONDENCE_PART_CODE_EA + "] returns no value");
}
suggestedCorrespondencePart.setCorrespondencePartType(correspondencePartType);
// The reason this is not implemented is that we are missing AdministrativeUnit and multiple users
CorrespondencePartInternalHateoas correspondencePartHateoas = new CorrespondencePartInternalHateoas(suggestedCorrespondencePart);
correspondencePartHateoasHandler.addLinksOnTemplate(correspondencePartHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body("");
}
use of nikita.common.model.noark5.v4.admin.AdministrativeUnit in project nikita-noark5-core by HiOA-ABI.
the class AdministrativeUnitDeserializer method deserialize.
@Override
public AdministrativeUnit deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
AdministrativeUnit administrativeUnit = new AdministrativeUnit();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise general properties
CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(administrativeUnit, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(administrativeUnit, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseNoarkFinaliseEntity(administrativeUnit, objectNode);
// Deserialize administrativeUnitStatus
JsonNode currentNode = objectNode.get(ADMINISTRATIVE_UNIT_STATUS);
if (currentNode != null) {
administrativeUnit.setAdministrativeUnitStatus(currentNode.textValue());
objectNode.remove(ADMINISTRATIVE_UNIT_STATUS);
}
// Deserialize administrativeUnitName
currentNode = objectNode.get(ADMINISTRATIVE_UNIT_NAME);
if (currentNode != null) {
administrativeUnit.setAdministrativeUnitName(currentNode.textValue());
objectNode.remove(ADMINISTRATIVE_UNIT_NAME);
}
// Deserialize shortName
currentNode = objectNode.get(SHORT_NAME);
if (currentNode != null) {
administrativeUnit.setShortName(currentNode.textValue());
objectNode.remove(SHORT_NAME);
}
// Deserialize referenceToParent
currentNode = objectNode.get(ADMINISTRATIVE_UNIT_PARENT_REFERENCE);
if (currentNode != null) {
AdministrativeUnit parentAdministrativeUnit = administrativeUnit.getParentAdministrativeUnit();
// Will it not always be null??
if (parentAdministrativeUnit == null) {
parentAdministrativeUnit = new AdministrativeUnit();
parentAdministrativeUnit.setSystemId(currentNode.textValue());
parentAdministrativeUnit.getReferenceChildAdministrativeUnit().add(administrativeUnit);
}
objectNode.remove(ADMINISTRATIVE_UNIT_PARENT_REFERENCE);
}
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
throw new NikitaMalformedInputDataException("The administrativEnhet you tried to create is malformed. The " + "following fields are not recognised as administrativEnhet fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
}
return administrativeUnit;
}
Aggregations