Esempio n. 1
0
 private void addProfileDesc(XMLStreamWriter sw, Description desc) {
   tag(
       sw,
       "profiledesc",
       () -> {
         tag(
             sw,
             "creation",
             () -> {
               characters(sw, resourceAsString("export-boilerplate.txt"));
               DateTime now = DateTime.now();
               tag(sw, "date", now.toString(), attrs("normal", unitDateNormalFormat.print(now)));
             });
         tag(
             sw,
             "langusage",
             () ->
                 tag(
                     sw,
                     "language",
                     LanguageHelpers.codeToName(desc.getLanguageOfDescription()),
                     attrs("langcode", desc.getLanguageOfDescription())));
         Optional.ofNullable(desc.<String>getProperty(IsadG.rulesAndConventions))
             .ifPresent(value -> tag(sw, "descrules", value, attrs("encodinganalog", "3.7.2")));
       });
 }
Esempio n. 2
0
  /**
   * Subclasses can override this method to cater to their special needs for
   * UndeterminedRelationships by default, it expects something like this in the original EAD:
   *
   * <p>
   *
   * <pre>{@code
   * <persname source="terezin-victims" authfilenumber="PERSON.ITI.1514982">Kien,
   * Leonhard (* 11.5.1886)</persname>
   * }</pre>
   *
   * <p>it works in unison with the extractRelations() method.
   *
   * @param unit the current unit
   */
  protected void solveUndeterminedRelationships(DocumentaryUnit unit) throws ValidationError {
    // Try to resolve the undetermined relationships
    // we can only create the annotations after the DocumentaryUnit
    // and its Description have been added to the graph,
    // so they have IDs.
    Api api = ApiFactory.noLogging(framedGraph, actioner.as(UserProfile.class));
    Bundle linkBundle =
        new Bundle(EntityClass.LINK)
            .withDataValue(Ontology.LINK_HAS_DESCRIPTION, RESOLVED_LINK_DESC);

    for (Description desc : unit.getDescriptions()) {
      // Put the set of relationships into a HashSet to remove duplicates.
      for (AccessPoint rel : Sets.newHashSet(desc.getAccessPoints())) {
        // the wp2 undetermined relationship that can be resolved have a 'cvoc' and a 'concept'
        // attribute.
        // they need to be found in the vocabularies that are in the graph
        if (rel.getPropertyKeys().contains("cvoc")) {
          String vocab = rel.getProperty("cvoc");
          String conceptId = rel.getProperty("concept");
          if (conceptId == null) {
            conceptId = rel.getProperty("target");
          }
          logger.debug("cvoc: {}, concept: {}", vocab, conceptId);
          try {
            Vocabulary vocabulary = manager.getEntity(vocab, Vocabulary.class);
            for (Concept concept : vocabulary.getConcepts()) {
              logger.debug("********************* {} {}", concept.getId(), concept.getIdentifier());
              if (concept.getIdentifier().equalsIgnoreCase(conceptId)) {
                try {
                  // TODO: Fix link type here...
                  Bundle data = linkBundle.withDataValue(Ontology.LINK_HAS_TYPE, "associative");
                  Link link = api.create(data, Link.class);
                  unit.addLink(link);
                  concept.addLink(link);
                  link.addLinkBody(rel);
                  logger.debug("link created between {} and {}", conceptId, concept.getId());
                } catch (PermissionDenied | DeserializationError ex) {
                  logger.error(ex.getMessage());
                }
              }
            }
          } catch (ItemNotFound ex) {
            logger.error("Vocabulary with id {} not found: {}", vocab, ex.getMessage());
          }
        } else {
          logger.debug("no cvoc found");
        }
      }
    }
  }
Esempio n. 3
0
  private void addControlAccess(XMLStreamWriter sw, Description desc) {
    Map<AccessPointType, List<AccessPoint>> byType = Maps.newHashMap();
    for (AccessPoint accessPoint : desc.getAccessPoints()) {
      AccessPointType type = accessPoint.getRelationshipType();
      if (controlAccessMappings.containsKey(type)) {
        if (byType.containsKey(type)) {
          byType.get(type).add(accessPoint);
        } else {
          byType.put(type, Lists.newArrayList(accessPoint));
        }
      }
    }

    for (Map.Entry<AccessPointType, List<AccessPoint>> entry : byType.entrySet()) {
      tag(
          sw,
          "controlaccess",
          () -> {
            AccessPointType type = entry.getKey();
            for (AccessPoint accessPoint : entry.getValue()) {
              tag(sw, controlAccessMappings.get(type), accessPoint.getName());
            }
          });
    }
  }
Esempio n. 4
0
 private void addFileDesc(
     XMLStreamWriter sw, String langCode, Repository repository, Description desc) {
   tag(
       sw,
       "filedesc",
       () -> {
         tag(sw, "titlestmt", () -> tag(sw, "titleproper", desc.getName()));
         tag(
             sw,
             "publicationstmt",
             () -> {
               LanguageHelpers.getBestDescription(repository, Optional.empty(), langCode)
                   .ifPresent(
                       repoDesc -> {
                         tag(sw, "publisher", repoDesc.getName());
                         for (Address address :
                             repoDesc.as(RepositoryDescription.class).getAddresses()) {
                           tag(
                               sw,
                               "address",
                               () -> {
                                 for (ContactInfo key : addressKeys) {
                                   for (Object v : coerceList(address.getProperty(key))) {
                                     tag(sw, "addressline", v.toString());
                                   }
                                 }
                                 tag(
                                     sw,
                                     "addressline",
                                     LanguageHelpers.countryCodeToName(
                                         repository.getCountry().getId()));
                               });
                         }
                       });
             });
         if (Description.CreationProcess.IMPORT.equals(desc.getCreationProcess())) {
           tag(
               sw,
               ImmutableList.of("notestmt", "note", "p"),
               resourceAsString("creationprocess-boilerplate.txt"));
         }
       });
 }
Esempio n. 5
0
  private void addDataSection(
      XMLStreamWriter sw,
      Repository repository,
      DocumentaryUnit subUnit,
      Description desc,
      String langCode) {
    tag(
        sw,
        "did",
        () -> {
          tag(sw, "unitid", subUnit.getIdentifier());
          tag(sw, "unittitle", desc.getName(), attrs("encodinganalog", "3.1.2"));

          for (DatePeriod datePeriod : desc.as(DocumentaryUnitDescription.class).getDatePeriods()) {
            if (DatePeriod.DatePeriodType.creation.equals(datePeriod.getDateType())) {
              String start = datePeriod.getStartDate();
              String end = datePeriod.getEndDate();
              if (start != null && end != null) {
                DateTime startDateTime = new DateTime(start);
                DateTime endDateTime = new DateTime(end);
                String normal =
                    String.format(
                        "%s/%s",
                        unitDateNormalFormat.print(startDateTime),
                        unitDateNormalFormat.print(endDateTime));
                String text =
                    String.format("%s/%s", startDateTime.year().get(), endDateTime.year().get());
                tag(sw, "unitdate", text, attrs("normal", normal, "encodinganalog", "3.1.3"));
              } else if (start != null) {
                DateTime startDateTime = new DateTime(start);
                String normal = String.format("%s", unitDateNormalFormat.print(startDateTime));
                String text = String.format("%s", startDateTime.year().get());
                tag(sw, "unitdate", text, attrs("normal", normal, "encodinganalog", "3.1.3"));
              }
            }
          }

          Set<String> propertyKeys = desc.getPropertyKeys();
          for (Map.Entry<IsadG, String> pair : textDidMappings.entrySet()) {
            if (propertyKeys.contains(pair.getKey().name())) {
              for (Object v : coerceList(desc.getProperty(pair.getKey()))) {
                tag(sw, pair.getValue(), v.toString(), textFieldAttrs(pair.getKey()));
              }
            }
          }

          if (propertyKeys.contains(IsadG.languageOfMaterial.name())) {
            tag(
                sw,
                "langmaterial",
                () -> {
                  for (Object v : coerceList(desc.getProperty(IsadG.languageOfMaterial))) {
                    String langName = LanguageHelpers.codeToName(v.toString());
                    if (v.toString().length() != 3) {
                      tag(sw, "language", langName, textFieldAttrs(IsadG.languageOfMaterial));
                    } else {
                      tag(
                          sw,
                          "language",
                          langName,
                          textFieldAttrs(IsadG.languageOfMaterial, "langcode", v.toString()));
                    }
                  }
                });
          }

          Optional.ofNullable(repository)
              .ifPresent(
                  repo -> {
                    LanguageHelpers.getBestDescription(repo, Optional.empty(), langCode)
                        .ifPresent(
                            repoDesc ->
                                tag(
                                    sw,
                                    "repository",
                                    () -> tag(sw, "corpname", repoDesc.getName())));
                  });
        });
  }