use of org.mycore.pi.MCRPIRegistrationInfo in project mycore by MyCoRe-Org.
the class MCRURNGranularRESTRegistrationTaskTest method run.
@Ignore
@Test
public void run() throws Exception {
MCRPI urn1 = generateMCRPI(randomFilename(), countRegistered);
MCREntityManagerProvider.getCurrentEntityManager().persist(urn1);
Assert.assertNull("Registered date should be null.", urn1.getRegistered());
MCRPersistentIdentifierManager.getInstance().getUnregisteredIdentifiers(urn1.getType()).stream().map(MCRPIRegistrationInfo::getIdentifier).map("URN: "::concat).forEach(LOGGER::info);
Integer progressedIdentifiersFromDatabase;
Function<MCRPIRegistrationInfo, Optional<Date>> registerFn = MCRPIUtils.getMCRURNClient()::register;
do {
progressedIdentifiersFromDatabase = MCRPersistentIdentifierManager.getInstance().setRegisteredDateForUnregisteredIdenifiers(MCRDNBURN.TYPE, registerFn, BATCH_SIZE);
} while (progressedIdentifiersFromDatabase > 0);
boolean registered = MCRPersistentIdentifierManager.getInstance().isRegistered(urn1);
LOGGER.info("Registered: {}", registered);
MCRPI mcrpi = MCREntityManagerProvider.getCurrentEntityManager().find(MCRPI.class, urn1.getId());
Optional.ofNullable(mcrpi).filter(pi -> pi.getRegistered() != null).map(MCRPI::getRegistered).map(Date::toString).map("URN registered: "::concat).ifPresent(LOGGER::info);
MCRPersistentIdentifierManager.getInstance().getUnregisteredIdentifiers(urn1.getType()).stream().map(MCRPIRegistrationInfo::getIdentifier).map("URN update: "::concat).forEach(LOGGER::info);
LOGGER.info("end.");
}
use of org.mycore.pi.MCRPIRegistrationInfo in project mycore by MyCoRe-Org.
the class MCRCountingDNBURNGenerator method readCountFromDatabase.
protected AtomicInteger readCountFromDatabase(String countPattern) {
Pattern regExpPattern = Pattern.compile(countPattern);
Predicate<String> matching = regExpPattern.asPredicate();
List<MCRPIRegistrationInfo> list = MCRPersistentIdentifierManager.getInstance().getList(MCRDNBURN.TYPE, -1, -1);
// extract the number of the PI
Optional<Integer> highestNumber = list.stream().map(MCRPIRegistrationInfo::getIdentifier).filter(matching).map(pi -> {
// extract the number of the PI
Matcher matcher = regExpPattern.matcher(pi);
if (matcher.find() && matcher.groupCount() == 1) {
String group = matcher.group(1);
return Integer.parseInt(group, 10);
} else {
return null;
}
}).filter(Objects::nonNull).min(Comparator.reverseOrder()).map(n -> n + 1);
return new AtomicInteger(highestNumber.orElse(0));
}
use of org.mycore.pi.MCRPIRegistrationInfo in project mycore by MyCoRe-Org.
the class MCRPersistentIdentifierRegistrationResource method listByType.
@GET
@Path("type/{type}")
@Produces(MediaType.APPLICATION_JSON)
public Response listByType(@PathParam("type") String type, @DefaultValue("0") @QueryParam("from") int from, @DefaultValue("50") @QueryParam("size") int size) {
Response errorResponse = validateParameters(from, size);
if (errorResponse != null)
return errorResponse;
List<MCRPIRegistrationInfo> mcrpiRegistrationInfos = MCRPersistentIdentifierManager.getInstance().getList(type, from, size);
return Response.status(Response.Status.OK).entity(new Gson().toJson(new MCRPIListJSON(type, from, size, MCRPersistentIdentifierManager.getInstance().getCount(type), mcrpiRegistrationInfos))).build();
}
use of org.mycore.pi.MCRPIRegistrationInfo in project mycore by MyCoRe-Org.
the class MCRPersistentIdentifierRegistrationResource method list.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response list(@DefaultValue("0") @QueryParam("from") int from, @DefaultValue("50") @QueryParam("size") int size) {
Response errorResponse = validateParameters(from, size);
if (errorResponse != null)
return errorResponse;
List<MCRPIRegistrationInfo> mcrpiRegistrationInfos = MCRPersistentIdentifierManager.getInstance().getList(from, size);
return Response.status(Response.Status.OK).entity(new Gson().toJson(new MCRPIListJSON(null, from, size, MCRPersistentIdentifierManager.getInstance().getCount(), mcrpiRegistrationInfos))).build();
}
use of org.mycore.pi.MCRPIRegistrationInfo in project mycore by MyCoRe-Org.
the class MCRURNGranularRESTRegistrationServiceTest method fullRegister.
@Test
public void fullRegister() throws Exception {
new MockContentTypes();
new MockFrontendUtil();
new MockFiles();
new MockAccessManager();
new MockObjectDerivate();
new MockDerivate();
MockMetadataManager mockMetadataManager = new MockMetadataManager();
MCRDerivate derivate = new MCRDerivate();
MCRObjectID mcrObjectID = MCRPIUtils.getNextFreeID();
derivate.setId(mcrObjectID);
mockMetadataManager.put(mcrObjectID, derivate);
Function<MCRDerivate, Stream<MCRPath>> foo = deriv -> IntStream.iterate(0, i -> i + 1).mapToObj(i -> "/foo/" + UUID.randomUUID() + "_" + String.format(Locale.getDefault(), "%02d", i)).map(f -> MCRPath.getPath(derivate.getId().toString(), f)).limit(numOfDerivFiles);
String serviceID = "TestService";
MCRURNGranularRESTRegistrationService testService = new MCRURNGranularRESTRegistrationService(serviceID, foo);
testService.register(derivate, "", true);
timerTask();
List<MCRPIRegistrationInfo> registeredURNs = MCREntityManagerProvider.getEntityManagerFactory().createEntityManager().createNamedQuery("Get.PI.Created", MCRPIRegistrationInfo.class).setParameter("mcrId", mcrObjectID.toString()).setParameter("type", MCRDNBURN.TYPE).setParameter("service", serviceID).getResultList();
Assert.assertEquals("Wrong number of registered URNs: ", numOfDerivFiles + 1, registeredURNs.size());
}
Aggregations