public static String generateUniqueId(String type) { MongoCollection idSeed = MongoDBController.getCollection(CollectionNames.idcollection); ID id = idSeed.findOne().as(ID.class); int uniqueNumber = id.val.intValue(); id.val = new Integer(uniqueNumber + 1); idSeed.update("{val: #}", uniqueNumber).upsert().with("{val : #}", (uniqueNumber + 1)); // idSeed.update().with("{val : " + id.val + "}"); DateTime now = DateTime.now(); String uniqueId = now.year().getAsString() + now.monthOfYear().getAsString() + type + uniqueNumber; return uniqueId; }
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()))); }); }); }