Search in sources :

Example 41 with DocumentDescription

use of nikita.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.

the class RecordService method createDocumentDescriptionAssociatedWithRecord.

@Override
public DocumentDescription createDocumentDescriptionAssociatedWithRecord(String systemID, DocumentDescription documentDescription) {
    DocumentDescription persistedDocumentDescription = null;
    Record record = recordRepository.findBySystemIdOrderBySystemId(systemID);
    if (record == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Record, using systemID " + systemID;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        TreeSet<Record> records = (TreeSet<Record>) documentDescription.getReferenceRecord();
        if (records == null) {
            records = new TreeSet<>();
            documentDescription.setReferenceRecord(records);
        }
        records.add(record);
        Set<DocumentDescription> documentDescriptions = record.getReferenceDocumentDescription();
        documentDescriptions.add(documentDescription);
        persistedDocumentDescription = documentDescriptionService.save(documentDescription);
    }
    return persistedDocumentDescription;
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) Record(nikita.model.noark5.v4.Record) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 42 with DocumentDescription

use of nikita.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.

the class RegistryEntryService method createDocumentDescriptionAssociatedWithRegistryEntry.

@Override
public DocumentDescription createDocumentDescriptionAssociatedWithRegistryEntry(String systemID, DocumentDescription documentDescription) {
    RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
    TreeSet<Record> records = (TreeSet<Record>) documentDescription.getReferenceRecord();
    // It should always be instaniated ... check this ...
    if (records == null) {
        records = new TreeSet<>();
        documentDescription.setReferenceRecord(records);
    }
    records.add(registryEntry);
    return documentDescriptionService.save(documentDescription);
}
Also used : TreeSet(java.util.TreeSet) Record(nikita.model.noark5.v4.Record) RegistryEntry(nikita.model.noark5.v4.casehandling.RegistryEntry)

Example 43 with DocumentDescription

use of nikita.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.

the class NoarkImportService method checkAndSetDefaultValues.

/**
     *
     * Check a Noark entity (fonds, series, file, etc) for valid properties and set any values that have not been set
     * that should be set with default values.
     *
     * @param entity
     * @throws Exception
     */
public void checkAndSetDefaultValues(INoarkGeneralEntity entity) throws Exception {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    // Not all Noark objects, i.e DocumentDescription and DocumentObject have a documentMedium property
    if (entity instanceof IDocumentMedium) {
        if (!NoarkUtils.NoarkEntity.Create.checkDocumentMediumValid(((IDocumentMedium) entity))) {
            logger.error("Document medium not a valid document medium. Assigned value is " + ((IDocumentMedium) entity).getDocumentMedium());
        // An exception will be thrown  by checkDocumentMediumValid if not valid
        //TODO: Look at the logic here, as a change checkDocumentMediumValid kinda makes
        // the if redundant
        }
    }
    // uniqueness via systemId
    if (entity.getSystemId() == null) {
        entity.setSystemId(UUID.randomUUID().toString());
    } else if (entity.getSystemId().length() != Constants.UUIDLength) {
        String randomUUID = UUID.randomUUID().toString();
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a valid UUID. Original value [" + entity.getSystemId() + entity.toString() + "] is being changed and assigned with [" + randomUUID + "]");
        entity.setSystemId(randomUUID);
    }
    if (entity.getCreatedDate() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdDate value. createdDate is being set to [" + new Date().toString() + "]");
        entity.setCreatedDate(new Date());
    }
    if (entity.getCreatedBy() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
        entity.setCreatedBy(username);
    }
    if (entity.getOwnedBy() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
        entity.setOwnedBy(username);
    }
    entity.setDeleted(false);
}
Also used : IDocumentMedium(nikita.model.noark5.v4.interfaces.IDocumentMedium) Date(java.util.Date)

Example 44 with DocumentDescription

use of nikita.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.

the class RecordImportService method createDocumentDescriptionAssociatedWithRecord.

@Override
public DocumentDescription createDocumentDescriptionAssociatedWithRecord(String systemID, DocumentDescription documentDescription) {
    DocumentDescription persistedDocumentDescription = null;
    Record record = recordRepository.findBySystemIdOrderBySystemId(systemID);
    if (record == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Record, using systemID " + systemID;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        TreeSet<Record> records = (TreeSet<Record>) documentDescription.getReferenceRecord();
        if (records == null) {
            records = new TreeSet<>();
            documentDescription.setReferenceRecord(records);
        }
        records.add(record);
        persistedDocumentDescription = documentDescriptionImportService.save(documentDescription);
    }
    return persistedDocumentDescription;
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) TreeSet(java.util.TreeSet) Record(nikita.model.noark5.v4.Record) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 45 with DocumentDescription

use of nikita.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.

the class RegistryEntryImportService method createDocumentDescriptionAssociatedWithRegistryEntry.

@Override
public DocumentDescription createDocumentDescriptionAssociatedWithRegistryEntry(String systemID, DocumentDescription documentDescription) {
    DocumentDescription persistedDocumentDescription = null;
    RegistryEntry registryEntry = registryEntryRepository.findBySystemIdOrderBySystemId(systemID);
    if (registryEntry == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " RegistryEntry, using registryEntrySystemId " + systemID;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        TreeSet<Record> records = (TreeSet<Record>) documentDescription.getReferenceRecord();
        if (records == null) {
            records = new TreeSet<>();
            documentDescription.setReferenceRecord(records);
        }
        records.add(registryEntry);
        persistedDocumentDescription = documentDescriptionImportService.save(documentDescription);
    }
    return persistedDocumentDescription;
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) TreeSet(java.util.TreeSet) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) Record(nikita.model.noark5.v4.Record) RegistryEntry(nikita.model.noark5.v4.casehandling.RegistryEntry)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)34 ApiOperation (io.swagger.annotations.ApiOperation)34 ApiResponses (io.swagger.annotations.ApiResponses)34 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)18 Timed (com.codahale.metrics.annotation.Timed)17 Authorisation (nikita.webapp.security.Authorisation)15 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)15 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)14 Record (nikita.model.noark5.v4.Record)8 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)8 AfterNoarkEntityDeletedEvent (nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)8 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)7 ArrayList (java.util.ArrayList)6 Record (nikita.common.model.noark5.v4.Record)6 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)6 NikitaException (nikita.common.util.exceptions.NikitaException)5 NikitaException (nikita.util.exceptions.NikitaException)5 List (java.util.List)4 Class (nikita.common.model.noark5.v4.Class)4 DocumentDescriptionHateoas (nikita.common.model.noark5.v4.hateoas.DocumentDescriptionHateoas)4