Search in sources :

Example 6 with DocumentType

use of nikita.common.model.noark5.v4.metadata.DocumentType in project nikita-noark5-core by HiOA-ABI.

the class DocumentTypeService method findByCode.

/**
 * retrieve all documentType that have a particular code.
 * <br>
 * Note, this will be replaced by OData search.
 *
 * @param code
 * @return A list of documentType objects wrapped as a MetadataHateoas
 * object
 */
@Override
public MetadataHateoas findByCode(String code) {
    MetadataHateoas metadataHateoas = new MetadataHateoas((List<INikitaEntity>) (List) documentTypeRepository.findByCode(code), DOCUMENT_TYPE);
    metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
    return metadataHateoas;
}
Also used : INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) List(java.util.List) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)

Example 7 with DocumentType

use of nikita.common.model.noark5.v4.metadata.DocumentType in project nikita-noark5-core by HiOA-ABI.

the class DocumentTypeService method createNewDocumentType.

// All CREATE operations
/**
 * Persists a new documentType object to the database.
 *
 * @param documentType documentType object with values set
 * @return the newly persisted documentType object wrapped as a
 * MetadataHateoas object
 */
@Override
public MetadataHateoas createNewDocumentType(DocumentType documentType) {
    documentType.setDeleted(false);
    documentType.setOwnedBy(SecurityContextHolder.getContext().getAuthentication().getName());
    MetadataHateoas metadataHateoas = new MetadataHateoas(documentTypeRepository.save(documentType));
    metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
    return metadataHateoas;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)

Example 8 with DocumentType

use of nikita.common.model.noark5.v4.metadata.DocumentType in project nikita-noark5-core by HiOA-ABI.

the class DocumentTypeService method handleUpdate.

/**
 * Update a documentType identified by its systemId
 * <p>
 * Copy the values you are allowed to change, code and description
 *
 * @param documentType
 * @return the updated documentType
 */
@Override
public MetadataHateoas handleUpdate(String systemId, Long version, DocumentType documentType) {
    DocumentType existingDocumentType = getDocumentTypeOrThrow(systemId);
    // Copy all the values you are allowed to copy ....
    if (null != existingDocumentType.getCode()) {
        existingDocumentType.setCode(existingDocumentType.getCode());
    }
    if (null != existingDocumentType.getDescription()) {
        existingDocumentType.setDescription(existingDocumentType.getDescription());
    }
    // Note this can potentially result in a NoarkConcurrencyException
    // exception
    existingDocumentType.setVersion(version);
    MetadataHateoas documentTypeHateoas = new MetadataHateoas(documentTypeRepository.save(existingDocumentType));
    metadataHateoasHandler.addLinks(documentTypeHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingDocumentType));
    return documentTypeHateoas;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) DocumentType(nikita.common.model.noark5.v4.metadata.DocumentType) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Example 9 with DocumentType

use of nikita.common.model.noark5.v4.metadata.DocumentType in project nikita-noark5-core by HiOA-ABI.

the class DocumentTypeService method findAll.

// All READ operations
/**
 * Retrieve a list of all documentType objects
 *
 * @return list of documentType objects wrapped as a MetadataHateoas object
 */
@Override
public MetadataHateoas findAll() {
    MetadataHateoas metadataHateoas = new MetadataHateoas((List<INikitaEntity>) (List) documentTypeRepository.findAll(), DOCUMENT_TYPE);
    metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
    return metadataHateoas;
}
Also used : INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) List(java.util.List) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)

Example 10 with DocumentType

use of nikita.common.model.noark5.v4.metadata.DocumentType in project nikita-noark5-core by HiOA-ABI.

the class DocumentDescriptionDeserializer method deserialize.

@Override
public DocumentDescription deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    DocumentDescription documentDescription = new DocumentDescription();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentDescription, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentDescription, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkTitleDescriptionEntity(documentDescription, objectNode, errors);
    // Deserialize documentType
    JsonNode currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    if (null != currentNode) {
        documentDescription.setDocumentType(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    }
    // Deserialize documentStatus
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_STATUS);
    if (null != currentNode) {
        documentDescription.setDocumentStatus(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_STATUS);
    }
    // Deserialize associatedWithRecordAs
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    if (null != currentNode) {
        documentDescription.setAssociatedWithRecordAs(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    }
    // Deserialize documentNumber
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    if (null != currentNode) {
        documentDescription.setDocumentNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    }
    // Deserialize associationDate
    documentDescription.setAssociationDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATION_DATE, objectNode, errors));
    // Deserialize associatedBy
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    if (null != currentNode) {
        documentDescription.setAssociatedBy(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    }
    // Deserialize storageLocation
    currentNode = objectNode.get(N5ResourceMappings.STORAGE_LOCATION);
    if (null != currentNode) {
        documentDescription.setStorageLocation(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.STORAGE_LOCATION);
    }
    // Deserialize general documentDescription properties
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(documentDescription, objectNode, errors);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The dokumentbeskrivelse you tried to create is malformed. The " + "following fields are not recognised as dokumentbeskrivelse fields[" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return documentDescription;
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Aggregations

MetadataHateoas (nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)6 Authorisation (nikita.webapp.security.Authorisation)6 List (java.util.List)3 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)3 DocumentType (nikita.common.model.noark5.v4.metadata.DocumentType)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)1 NikitaMalformedInputDataException (nikita.common.util.exceptions.NikitaMalformedInputDataException)1 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)1 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)1 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)1 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)1