Search in sources :

Example 81 with Record

use of nikita.common.model.noark5.v4.Record in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV2Test method getRecordElement.

private Record getRecordElement() {
    Record r = new Record();
    r.setActivitiesSummary(getActivitiesSummaryElement());
    r.setPerson(getPersonElement());
    return r;
}
Also used : Record(org.orcid.jaxb.model.record_v2.Record)

Example 82 with Record

use of nikita.common.model.noark5.v4.Record in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV2Test method checkIsPublicRecordTest.

@Test
public void checkIsPublicRecordTest() {
    Record r = getRecordElement();
    publicAPISecurityManagerV2.filter(r);
    // Verify activities - nothing filtered
    ActivitiesSummary as = r.getActivitiesSummary();
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    // Verify bio sections - nothing filtered
    Person p = r.getPerson();
    assertEquals(3, p.getAddresses().getAddress().size());
    assertAllArePublic(p.getAddresses().getAddress());
    assertEquals(3, p.getEmails().getEmails().size());
    assertAllArePublic(p.getEmails().getEmails());
    assertEquals(3, p.getExternalIdentifiers().getExternalIdentifiers().size());
    assertAllArePublic(p.getExternalIdentifiers().getExternalIdentifiers());
    assertEquals(3, p.getKeywords().getKeywords().size());
    assertAllArePublic(p.getKeywords().getKeywords());
    assertEquals(3, p.getOtherNames().getOtherNames().size());
    assertAllArePublic(p.getOtherNames().getOtherNames());
    assertEquals(3, p.getResearcherUrls().getResearcherUrls().size());
    assertAllArePublic(p.getResearcherUrls().getResearcherUrls());
    assertNotNull(p.getBiography());
    assertNotNull(p.getName());
    // Filter biography, name, educations and funding
    r = getRecordElement();
    r.getPerson().getBiography().setVisibility(Visibility.LIMITED);
    r.getPerson().getName().setVisibility(Visibility.LIMITED);
    setVisibility(r.getActivitiesSummary().getEducations().getSummaries(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    setVisibility(r.getActivitiesSummary().getFundings(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV2.filter(r);
    // Verify activities - educations and funding filtered
    as = r.getActivitiesSummary();
    assertNotNull(as.getEducations());
    assertTrue(as.getEducations().getSummaries().isEmpty());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertTrue(as.getFundings().getFundingGroup().isEmpty());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    // Verify bio sections - bio and name filtered
    p = r.getPerson();
    assertEquals(3, p.getAddresses().getAddress().size());
    assertEquals(3, p.getEmails().getEmails().size());
    assertEquals(3, p.getExternalIdentifiers().getExternalIdentifiers().size());
    assertEquals(3, p.getKeywords().getKeywords().size());
    assertEquals(3, p.getOtherNames().getOtherNames().size());
    assertEquals(3, p.getResearcherUrls().getResearcherUrls().size());
    assertNull(p.getBiography());
    assertNull(p.getName());
    // Filter emails, external identifiers, peer reviews and works
    r = getRecordElement();
    setVisibility(r.getPerson().getEmails().getEmails(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    setVisibility(r.getPerson().getExternalIdentifiers().getExternalIdentifiers(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    setVisibility(r.getActivitiesSummary().getPeerReviews(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    setVisibility(r.getActivitiesSummary().getWorks(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV2.filter(r);
    // Verify activities - peer reviews and works filtered
    as = r.getActivitiesSummary();
    assertEquals(3, as.getEducations().getSummaries().size());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertTrue(as.getPeerReviews().getPeerReviewGroup().isEmpty());
    assertTrue(as.getWorks().getWorkGroup().isEmpty());
    // Verify bio sections - emails, external identifiers filtered
    p = r.getPerson();
    assertEquals(3, p.getAddresses().getAddress().size());
    assertNotNull(p.getEmails());
    assertTrue(p.getEmails().getEmails().isEmpty());
    assertNotNull(p.getExternalIdentifiers());
    assertTrue(p.getExternalIdentifiers().getExternalIdentifiers().isEmpty());
    assertEquals(3, p.getKeywords().getKeywords().size());
    assertEquals(3, p.getOtherNames().getOtherNames().size());
    assertEquals(3, p.getResearcherUrls().getResearcherUrls().size());
    assertNotNull(p.getBiography());
    assertNotNull(p.getName());
    // Filter keywords and other names
    r = getRecordElement();
    setVisibility(r.getPerson().getOtherNames().getOtherNames(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    setVisibility(r.getPerson().getKeywords().getKeywords(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV2.filter(r);
    // Verify activities - nothing filtered
    as = r.getActivitiesSummary();
    assertEquals(3, as.getEducations().getSummaries().size());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    // Verify bio sections - keywords and other names filtered
    p = r.getPerson();
    assertEquals(3, p.getAddresses().getAddress().size());
    assertEquals(3, p.getEmails().getEmails().size());
    assertEquals(3, p.getExternalIdentifiers().getExternalIdentifiers().size());
    assertNotNull(p.getKeywords());
    assertTrue(p.getKeywords().getKeywords().isEmpty());
    assertNotNull(p.getOtherNames());
    assertTrue(p.getOtherNames().getOtherNames().isEmpty());
    assertEquals(3, p.getResearcherUrls().getResearcherUrls().size());
    assertNotNull(p.getBiography());
    assertNotNull(p.getName());
}
Also used : Record(org.orcid.jaxb.model.record_v2.Record) Person(org.orcid.jaxb.model.record_v2.Person) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) Test(org.junit.Test)

Example 83 with Record

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

the class RecordDeserializer method deserialize.

@Override
public Record deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    Record record = new Record();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(record, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(record, objectNode);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(RECORD_ARCHIVED_BY);
    if (currentNode != null) {
        record.setArchivedBy(currentNode.textValue());
        objectNode.remove(RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    currentNode = objectNode.get(RECORD_ARCHIVED_DATE);
    if (currentNode != null) {
        try {
            Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
            record.setArchivedDate(parsedDate);
            objectNode.remove(RECORD_ARCHIVED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The registrering you tried to create " + "has a malformed arkivertDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The registrering you tried to create is malformed. The " + "following fields are not recognised as registrering fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return record;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Record(nikita.model.noark5.v4.Record) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 84 with Record

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

the class RegistryEntryDeserializer method deserialize.

@Override
public RegistryEntry deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    RegistryEntry registryEntry = new RegistryEntry();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(registryEntry, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(registryEntry, objectNode);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(RECORD_ARCHIVED_BY);
    if (null != currentNode) {
        registryEntry.setArchivedBy(currentNode.textValue());
        objectNode.remove(RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    currentNode = objectNode.get(RECORD_ARCHIVED_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
            registryEntry.setArchivedDate(parsedDate);
            objectNode.remove(RECORD_ARCHIVED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost object you tried to create " + "has a malformed arkivertDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize general basicRecord properties
    // Deserialize recordId
    currentNode = objectNode.get(BASIC_RECORD_ID);
    if (null != currentNode) {
        registryEntry.setRecordId(currentNode.textValue());
        objectNode.remove(BASIC_RECORD_ID);
    }
    // Deserialize title (not using utils to preserve order)
    currentNode = objectNode.get(TITLE);
    if (null != currentNode) {
        registryEntry.setTitle(currentNode.textValue());
        objectNode.remove(TITLE);
    }
    // Deserialize  officialTitle
    currentNode = objectNode.get(FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        registryEntry.setOfficialTitle(currentNode.textValue());
        objectNode.remove(FILE_PUBLIC_TITLE);
    }
    // Deserialize description
    currentNode = objectNode.get(DESCRIPTION);
    if (null != currentNode) {
        registryEntry.setDescription(currentNode.textValue());
        objectNode.remove(DESCRIPTION);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(registryEntry, objectNode);
    // Deserialize general registryEntry properties
    // Deserialize recordYear
    currentNode = objectNode.get(REGISTRY_ENTRY_YEAR);
    if (null != currentNode) {
        registryEntry.setRecordYear(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(REGISTRY_ENTRY_YEAR);
    }
    // Deserialize recordSequenceNumber
    currentNode = objectNode.get(REGISTRY_ENTRY_SEQUENCE_NUMBER);
    if (null != currentNode) {
        registryEntry.setRecordSequenceNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(REGISTRY_ENTRY_SEQUENCE_NUMBER);
    }
    // Deserialize registryEntryNumber
    currentNode = objectNode.get(REGISTRY_ENTRY_NUMBER);
    if (null != currentNode) {
        registryEntry.setRegistryEntryNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(REGISTRY_ENTRY_NUMBER);
    }
    // Deserialize registryEntryType
    currentNode = objectNode.get(REGISTRY_ENTRY_TYPE);
    if (null != currentNode) {
        registryEntry.setRegistryEntryType(currentNode.textValue());
        objectNode.remove(REGISTRY_ENTRY_TYPE);
    }
    // Deserialize recordStatus
    currentNode = objectNode.get(REGISTRY_ENTRY_STATUS);
    if (null != currentNode) {
        registryEntry.setRecordStatus(currentNode.textValue());
        objectNode.remove(REGISTRY_ENTRY_STATUS);
    }
    // Deserialize recordDate
    currentNode = objectNode.get(REGISTRY_ENTRY_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setRecordDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed journaldato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize documentDate
    currentNode = objectNode.get(REGISTRY_ENTRY_DOCUMENT_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setDocumentDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_DOCUMENT_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed dokumentetsDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize receivedDate
    currentNode = objectNode.get(REGISTRY_ENTRY_RECEIVED_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setReceivedDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_RECEIVED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed mottattDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize sentDate
    currentNode = objectNode.get(REGISTRY_ENTRY_SENT_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setSentDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_SENT_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed sendtDate. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize dueDate
    currentNode = objectNode.get(REGISTRY_ENTRY_DUE_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setDueDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_DUE_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed forfallsdato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize freedomAssessmentDate
    currentNode = objectNode.get(REGISTRY_ENTRY_RECORD_FREEDOM_ASSESSMENT_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setFreedomAssessmentDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_RECORD_FREEDOM_ASSESSMENT_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed offentlighetsvurdertDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize numberOfAttachments
    currentNode = objectNode.get(REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
    if (null != currentNode) {
        registryEntry.setNumberOfAttachments(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
    }
    // Deserialize loanedDate
    currentNode = objectNode.get(CASE_LOANED_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setLoanedDate(parsedDate);
            objectNode.remove(CASE_LOANED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed utlaantDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize loanedTo
    currentNode = objectNode.get(CASE_LOANED_TO);
    if (null != currentNode) {
        registryEntry.setLoanedTo(currentNode.textValue());
        objectNode.remove(CASE_LOANED_TO);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The journalpost you tried to create is malformed. The " + "following fields are not recognised as journalpost fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return registryEntry;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) RegistryEntry(nikita.model.noark5.v4.casehandling.RegistryEntry) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 85 with Record

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

the class RecordService method findRecordByOwnerPaginated.

// All READ operations
public List<Record> findRecordByOwnerPaginated(Integer top, Integer skip) {
    if (top == null || top > maxPageSize) {
        top = maxPageSize;
    }
    if (skip == null) {
        skip = 0;
    }
    String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Record> criteriaQuery = criteriaBuilder.createQuery(Record.class);
    Root<Record> from = criteriaQuery.from(Record.class);
    CriteriaQuery<Record> select = criteriaQuery.select(from);
    criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
    TypedQuery<Record> typedQuery = entityManager.createQuery(select);
    typedQuery.setFirstResult(skip);
    typedQuery.setMaxResults(maxPageSize);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Record(nikita.model.noark5.v4.Record)

Aggregations

Test (org.junit.Test)60 Record (org.orcid.jaxb.model.record_v2.Record)49 Counted (com.codahale.metrics.annotation.Counted)28 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponses (io.swagger.annotations.ApiResponses)27 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)21 Person (org.orcid.jaxb.model.record_v2.Person)20 Record (nikita.model.noark5.v4.Record)19 Email (org.orcid.jaxb.model.record_v2.Email)19 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)18 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)18 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)18 Address (org.orcid.jaxb.model.record_v2.Address)18 Keyword (org.orcid.jaxb.model.record_v2.Keyword)18 OtherName (org.orcid.jaxb.model.record_v2.OtherName)18 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)18 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)18 Name (org.orcid.jaxb.model.record_v2.Name)17 PeerReviewSummary (org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary)16