Search in sources :

Example 6 with Format

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

the class FormatService method createNewFormat.

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

Example 7 with Format

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

the class FormatService method find.

// find by systemId
/**
 * Retrieve a single Format object identified by systemId
 *
 * @param systemId systemId of the Format you wish to retrieve
 * @return single Format object wrapped as a MetadataHateoas object
 */
@Override
public MetadataHateoas find(String systemId) {
    MetadataHateoas metadataHateoas = new MetadataHateoas(formatRepository.save(formatRepository.findBySystemId(systemId)));
    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 Format

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

the class RegistryEntryTypeService method generateDefaultRegistryEntryType.

/**
 * Generate a default RegistryEntryType object
 *
 * @return the RegistryEntryType object
 */
@Override
public RegistryEntryType generateDefaultRegistryEntryType() {
    RegistryEntryType format = new RegistryEntryType();
    format.setCode(TEMPLATE_REGISTRY_ENTRY_TYPE_CODE);
    format.setDescription(TEMPLATE_REGISTRY_ENTRY_TYPE_DESCRIPTION);
    return format;
}
Also used : RegistryEntryType(nikita.common.model.noark5.v4.metadata.RegistryEntryType)

Example 9 with Format

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

the class RegistryEntryTypeService method getRegistryEntryTypeOrThrow.

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

Example 10 with Format

use of nikita.common.model.noark5.v4.metadata.Format 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)

Aggregations

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