Search in sources :

Example 6 with AfterNoarkEntityUpdatedEvent

use of nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent in project nikita-noark5-core by HiOA-ABI.

the class VariantFormatService method handleUpdate.

/**
 * Update a VariantFormat identified by its systemId
 * <p>
 * Copy the values you are allowed to change, code and description
 *
 * @param systemId      The systemId of the variantFormat object you wish to
 *                      update
 * @param variantFormat The updated variantFormat object. Note the values
 *                      you are allowed to change are copied from this
 *                      object. This object is not persisted.
 * @return the updated variantFormat
 */
@Override
public MetadataHateoas handleUpdate(String systemId, Long version, VariantFormat variantFormat) {
    VariantFormat existingVariantFormat = getVariantFormatOrThrow(systemId);
    // Copy all the values you are allowed to copy ....
    if (null != existingVariantFormat.getCode()) {
        existingVariantFormat.setCode(existingVariantFormat.getCode());
    }
    if (null != existingVariantFormat.getDescription()) {
        existingVariantFormat.setDescription(existingVariantFormat.getDescription());
    }
    // Note this can potentially result in a NoarkConcurrencyException
    // exception
    existingVariantFormat.setVersion(version);
    MetadataHateoas variantFormatHateoas = new MetadataHateoas(variantFormatRepository.save(existingVariantFormat));
    metadataHateoasHandler.addLinks(variantFormatHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingVariantFormat));
    return variantFormatHateoas;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) VariantFormat(nikita.common.model.noark5.v4.metadata.VariantFormat) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Example 7 with AfterNoarkEntityUpdatedEvent

use of nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordHateoasController method updateBasicRecord.

// API - All PUT Requests (CRUD - UPDATE)
// Update a BasicRecord
// PUT [contextPath][api]/arkivstruktur/basisregistrering/{systemID}
@ApiOperation(value = "Updates a BasicRecord object", notes = "Returns the newly" + " update BasicRecord object after it is persisted to the database", response = BasicRecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "BasicRecord " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = BasicRecordHateoas.class), @ApiResponse(code = 201, message = "BasicRecord " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = BasicRecordHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type BasicRecord"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.PUT, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<BasicRecordHateoas> updateBasicRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of basicRecord to update.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "basicRecord", value = "Incoming basicRecord object", required = true) @RequestBody BasicRecord basicRecord) throws NikitaException {
    validateForUpdate(basicRecord);
    BasicRecord updatedBasicRecord = basicRecordService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), basicRecord);
    BasicRecordHateoas basicRecordHateoas = new BasicRecordHateoas(updatedBasicRecord);
    basicRecordHateoasHandler.addLinks(basicRecordHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedBasicRecord));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedBasicRecord.getVersion().toString()).body(basicRecordHateoas);
}
Also used : Authorisation(nikita.webapp.security.Authorisation) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 8 with AfterNoarkEntityUpdatedEvent

use of nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent in project nikita-noark5-core by HiOA-ABI.

the class FondsService method findSingleFonds.

/**
 * Retrieve a list of StorageLocation objects associated with a given Fonds
 * from the database. First we try to locate the Fonds object. If the
 * Fonds object does not exist a NoarkEntityNotFoundException exception
 * is thrown that the caller has to deal with.
 *
 * If any StorageLocation objects exist, they are wrapped in a
 * StorageLocationHateoas object and returned to the caller.
 *
 * @param fondsSystemId The systemId of the Fonds object that you want to
 *                      retrieve associated StorageLocation objects
 *
 * @return the newly persisted fondsCreator object wrapped as a
 * StorageLocationHateoas object
 */
/*@Override
    TODO: Finish implementing this.
    public StorageLocationHateoas findStorageLocationAssociatedWithFonds(
            @NotNull String fondsSystemId) {

        Fonds fonds = getFondsOrThrow(fondsSystemId);

        StorageLocationHateoas stroageLocationHateoas = new
                StorageLocationHateoas((List<INikitaEntity>)
                (List) fonds.getReferenceStorageLocation());
        fondsCreatorHateoasHandler.addLinks(stroageLocationHateoas,
                new Authorisation());
        return stroageLocationHateoas;
    } */
/**
 * Retrieve a single Fonds objects from the database.
 *
 * @param fondsSystemId The systemId of the Fonds object you wish to
 *                      retrieve
 * @return the Fonds object wrapped as a FondsHateoas object
 */
@Override
public FondsHateoas findSingleFonds(String fondsSystemId) {
    Fonds existingFonds = getFondsOrThrow(fondsSystemId);
    FondsHateoas fondsHateoas = new FondsHateoas(fondsRepository.save(existingFonds));
    fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingFonds));
    return fondsHateoas;
}
Also used : FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Example 9 with AfterNoarkEntityUpdatedEvent

use of nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent in project nikita-noark5-core by HiOA-ABI.

the class FondsService method handleUpdate.

// All UPDATE operations
/**
 * Updates a Fonds object in the database. First we try to locate the
 * Fonds object. If the Fonds object does not exist a
 * NoarkEntityNotFoundException exception is thrown that the caller has
 * to deal with.
 * <br>
 * After this the values you are allowed to update are copied from the
 * incomingFonds object to the existingFonds object and the existingFonds
 * object will be persisted to the database when the transaction boundary
 * is over.
 * <p>
 * Note, the version corresponds to the version number, when the object
 * was initially retrieved from the database. If this number is not the
 * same as the version number when re-retrieving the Fonds object from
 * the database a NoarkConcurrencyException is thrown. Note. This happens
 * when the call to Fonds.setVersion() occurs.
 *
 * @param fondsSystemId The systemId of the fonds object to retrieve
 * @param version       The last known version number (derived from an ETAG)
 * @param incomingFonds The incoming fonds object
 */
@Override
public FondsHateoas handleUpdate(@NotNull String fondsSystemId, @NotNull Long version, @NotNull Fonds incomingFonds) {
    Fonds existingFonds = getFondsOrThrow(fondsSystemId);
    // Copy all the values you are allowed to copy ....
    if (null != incomingFonds.getDescription()) {
        existingFonds.setDescription(incomingFonds.getDescription());
    }
    if (null != incomingFonds.getTitle()) {
        existingFonds.setTitle(incomingFonds.getTitle());
    }
    if (null != incomingFonds.getDocumentMedium()) {
        existingFonds.setDocumentMedium(existingFonds.getDocumentMedium());
    }
    // Note this can potentially result in a NoarkConcurrencyException
    // exception
    existingFonds.setVersion(version);
    FondsHateoas fondsHateoas = new FondsHateoas(fondsRepository.save(existingFonds));
    fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingFonds));
    return fondsHateoas;
}
Also used : FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Example 10 with AfterNoarkEntityUpdatedEvent

use of nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent in project nikita-noark5-core by HiOA-ABI.

the class CasePartyRoleService method handleUpdate.

/**
 * Update a CasePartyRole identified by its systemId
 * <p>
 * Copy the values you are allowed to change, code and description
 *
 * @param systemId      The systemId of the casePartyRole object you wish to
 *                      update
 * @param casePartyRole The updated casePartyRole object. Note the values
 *                      you are allowed to change are copied from this
 *                      object. This object is not persisted.
 * @return the updated casePartyRole
 */
@Override
public MetadataHateoas handleUpdate(String systemId, Long version, CasePartyRole casePartyRole) {
    CasePartyRole existingCasePartyRole = getCasePartyRoleOrThrow(systemId);
    // Copy all the values you are allowed to copy ....
    if (null != existingCasePartyRole.getCode()) {
        existingCasePartyRole.setCode(existingCasePartyRole.getCode());
    }
    if (null != existingCasePartyRole.getDescription()) {
        existingCasePartyRole.setDescription(existingCasePartyRole.getDescription());
    }
    // Note this can potentially result in a NoarkConcurrencyException
    // exception
    existingCasePartyRole.setVersion(version);
    MetadataHateoas casePartyRoleHateoas = new MetadataHateoas(casePartyRoleRepository.save(existingCasePartyRole));
    metadataHateoasHandler.addLinks(casePartyRoleHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingCasePartyRole));
    return casePartyRoleHateoas;
}
Also used : CasePartyRole(nikita.common.model.noark5.v4.metadata.CasePartyRole) Authorisation(nikita.webapp.security.Authorisation) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Aggregations

Authorisation (nikita.webapp.security.Authorisation)34 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)34 MetadataHateoas (nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)17 Counted (com.codahale.metrics.annotation.Counted)15 ApiOperation (io.swagger.annotations.ApiOperation)14 ApiResponses (io.swagger.annotations.ApiResponses)14 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)3 Fonds (nikita.common.model.noark5.v4.Fonds)2 CaseFileHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)2 Class (nikita.common.model.noark5.v4.Class)1 ClassificationSystem (nikita.common.model.noark5.v4.ClassificationSystem)1 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)1 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)1 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)1 Record (nikita.common.model.noark5.v4.Record)1 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)1 RegistryEntry (nikita.common.model.noark5.v4.casehandling.RegistryEntry)1 CorrespondencePartInternal (nikita.common.model.noark5.v4.casehandling.secondary.CorrespondencePartInternal)1 CorrespondencePartPerson (nikita.common.model.noark5.v4.casehandling.secondary.CorrespondencePartPerson)1 CorrespondencePartUnit (nikita.common.model.noark5.v4.casehandling.secondary.CorrespondencePartUnit)1