Search in sources :

Example 1 with AdministrativeUnit

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);
}
Also used : AdministrativeUnit(nikita.model.noark5.v4.admin.AdministrativeUnit)

Example 2 with AdministrativeUnit

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;
}
Also used : AdministrativeUnit(nikita.model.noark5.v4.admin.AdministrativeUnit) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 3 with 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);
}
Also used : AdministrativeUnit(nikita.model.noark5.v4.admin.AdministrativeUnit) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) AdministrativeUnitHateoas(nikita.model.noark5.v4.hateoas.admin.AdministrativeUnitHateoas) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with AdministrativeUnit

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("");
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) CorrespondencePartType(nikita.model.noark5.v4.metadata.CorrespondencePartType) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with AdministrativeUnit

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AdministrativeUnit(nikita.model.noark5.v4.admin.AdministrativeUnit) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)12 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 AdministrativeUnit (nikita.model.noark5.v4.admin.AdministrativeUnit)7 Timed (com.codahale.metrics.annotation.Timed)6 AdministrativeUnit (nikita.common.model.noark5.v4.admin.AdministrativeUnit)6 AdministrativeUnitHateoas (nikita.common.model.noark5.v4.hateoas.admin.AdministrativeUnitHateoas)5 AdministrativeUnitHateoas (nikita.model.noark5.v4.hateoas.admin.AdministrativeUnitHateoas)5 Authorisation (nikita.webapp.security.Authorisation)5 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 NikitaMalformedInputDataException (nikita.common.util.exceptions.NikitaMalformedInputDataException)2 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Series (nikita.common.model.noark5.v4.Series)1 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)1