Search in sources :

Example 6 with VariantFormat

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

the class DocumentObjectDeserializer method deserialize.

@Override
public DocumentObject deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    DocumentObject documentObject = new DocumentObject();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general DocumentObject properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentObject, objectNode, errors);
    // Deserialize versionNumber
    JsonNode currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_VERSION_NUMBER);
    if (null != currentNode) {
        documentObject.setVersionNumber(new Integer(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_VERSION_NUMBER);
    }
    // Deserialize variantFormat
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_VARIANT_FORMAT);
    if (null != currentNode) {
        documentObject.setVariantFormat(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_VARIANT_FORMAT);
    }
    // Deserialize format
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_FORMAT);
    if (null != currentNode) {
        documentObject.setFormat(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_FORMAT);
    }
    // Deserialize formatDetails
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_FORMAT_DETAILS);
    if (null != currentNode) {
        documentObject.setFormatDetails(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_FORMAT_DETAILS);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentObject, objectNode, errors);
    // Deserialize referenceDocumentFile
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE);
    if (null != currentNode) {
        documentObject.setReferenceDocumentFile(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE);
    }
    // Deserialize checksum
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_CHECKSUM);
    if (null != currentNode) {
        documentObject.setChecksum(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_CHECKSUM);
    }
    // Deserialize checksumAlgorithm
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_CHECKSUM_ALGORITHM);
    if (null != currentNode) {
        documentObject.setChecksumAlgorithm(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_CHECKSUM_ALGORITHM);
    }
    // Deserialize fileSize
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_FILE_SIZE);
    if (null != currentNode) {
        documentObject.setFileSize(currentNode.asLong());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_FILE_SIZE);
    }
    // Deserialize filename
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_FILE_NAME);
    if (null != currentNode) {
        documentObject.setOriginalFilename(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_FILE_NAME);
    }
    // Deserialize mimeType
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_MIME_TYPE);
    if (null != currentNode) {
        documentObject.setMimeType(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_MIME_TYPE);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The dokumentobjekt you tried to create is malformed. The " + "following fields are not recognised as dokumentobjekt fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return documentObject;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DocumentObject(nikita.common.model.noark5.v4.DocumentObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 7 with VariantFormat

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

the class VariantFormatService method findByCode.

/**
 * retrieve all VariantFormat that have a particular code.
 * <br>
 * Note, this will be replaced by OData search.
 *
 * @param code The code of the object you wish to retrieve
 * @return A list of VariantFormat objects wrapped as a MetadataHateoas
 * object
 */
@Override
public MetadataHateoas findByCode(String code) {
    MetadataHateoas metadataHateoas = new MetadataHateoas((List<INikitaEntity>) (List) variantFormatRepository.findByCode(code), VARIANT_FORMAT);
    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 8 with VariantFormat

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

the class VariantFormatService method getVariantFormatOrThrow.

/**
 * 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 VariantFormat object back. If there
 * is no VariantFormat object, a NoarkEntityNotFoundException exception
 * is thrown
 *
 * @param systemId The systemId of the VariantFormat object to retrieve
 * @return the VariantFormat object
 */
private VariantFormat getVariantFormatOrThrow(@NotNull String systemId) {
    VariantFormat variantFormat = variantFormatRepository.findBySystemId(systemId);
    if (variantFormat == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " VariantFormat, using " + "systemId " + systemId;
        logger.error(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return variantFormat;
}
Also used : NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) VariantFormat(nikita.common.model.noark5.v4.metadata.VariantFormat)

Example 9 with VariantFormat

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

the class VariantFormatService method generateDefaultVariantFormat.

/**
 * Generate a default VariantFormat object
 *
 * @return the VariantFormat object wrapped as a VariantFormatHateoas object
 */
@Override
public VariantFormat generateDefaultVariantFormat() {
    VariantFormat variantFormat = new VariantFormat();
    variantFormat.setCode(TEMPLATE_VARIANT_FORMAT_CODE);
    variantFormat.setDescription(TEMPLATE_VARIANT_FORMAT_DESCRIPTION);
    return variantFormat;
}
Also used : VariantFormat(nikita.common.model.noark5.v4.metadata.VariantFormat)

Example 10 with VariantFormat

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

the class VariantFormatService method createNewVariantFormat.

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

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 VariantFormat (nikita.common.model.noark5.v4.metadata.VariantFormat)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)1 NikitaMalformedInputDataException (nikita.common.util.exceptions.NikitaMalformedInputDataException)1 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)1 DocumentObject (nikita.model.noark5.v4.DocumentObject)1 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)1 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)1