Search in sources :

Example 1 with MCRPIRegistrationInfo

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.");
}
Also used : MCRPIRegistrationInfo(org.mycore.pi.MCRPIRegistrationInfo) Optional(java.util.Optional) MCRPI(org.mycore.pi.backend.MCRPI) MCRPIUtils.generateMCRPI(org.mycore.pi.MCRPIUtils.generateMCRPI) Date(java.util.Date) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with MCRPIRegistrationInfo

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));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Objects(java.util.Objects) List(java.util.List) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Predicate(java.util.function.Predicate) Map(java.util.Map) Optional(java.util.Optional) MCRPersistentIdentifierManager(org.mycore.pi.MCRPersistentIdentifierManager) HashMap(java.util.HashMap) MCRPIRegistrationInfo(org.mycore.pi.MCRPIRegistrationInfo) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) Pattern(java.util.regex.Pattern) MCRPIRegistrationInfo(org.mycore.pi.MCRPIRegistrationInfo) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Objects(java.util.Objects)

Example 3 with MCRPIRegistrationInfo

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();
}
Also used : Response(javax.ws.rs.core.Response) MCRPIRegistrationInfo(org.mycore.pi.MCRPIRegistrationInfo) MCRPIListJSON(org.mycore.pi.frontend.model.MCRPIListJSON) Gson(com.google.gson.Gson) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with MCRPIRegistrationInfo

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();
}
Also used : Response(javax.ws.rs.core.Response) MCRPIRegistrationInfo(org.mycore.pi.MCRPIRegistrationInfo) MCRPIListJSON(org.mycore.pi.frontend.model.MCRPIListJSON) Gson(com.google.gson.Gson) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with MCRPIRegistrationInfo

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());
}
Also used : IntStream(java.util.stream.IntStream) Date(java.util.Date) MCRUUIDURNGenerator(org.mycore.pi.urn.MCRUUIDURNGenerator) Function(java.util.function.Function) MCRException(org.mycore.common.MCRException) TreeSet(java.util.TreeSet) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRAccessManager(org.mycore.access.MCRAccessManager) MCRDNBURN(org.mycore.pi.urn.MCRDNBURN) LinkOption(java.nio.file.LinkOption) Locale(java.util.Locale) MCRMetaIFS(org.mycore.datamodel.metadata.MCRMetaIFS) Map(java.util.Map) After(org.junit.After) Mock(mockit.Mock) MCRFileMetadata(org.mycore.datamodel.metadata.MCRFileMetadata) Path(java.nio.file.Path) MCRObjectDerivate(org.mycore.datamodel.metadata.MCRObjectDerivate) MockUp(mockit.MockUp) MCRContentTypes(org.mycore.datamodel.niofs.MCRContentTypes) Files(java.nio.file.Files) MCRPath(org.mycore.datamodel.niofs.MCRPath) IOException(java.io.IOException) Test(org.junit.Test) MCRPIRegistrationInfo(org.mycore.pi.MCRPIRegistrationInfo) UUID(java.util.UUID) MCRFrontendUtil(org.mycore.frontend.MCRFrontendUtil) TimeUnit(java.util.concurrent.TimeUnit) MCREntityManagerProvider(org.mycore.backend.jpa.MCREntityManagerProvider) List(java.util.List) Stream(java.util.stream.Stream) MCRStoreTestCase(org.mycore.common.MCRStoreTestCase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MockMetadataManager(org.mycore.pi.MockMetadataManager) MCRPIUtils(org.mycore.pi.MCRPIUtils) Assert(org.junit.Assert) MCRPIRegistrationInfo(org.mycore.pi.MCRPIRegistrationInfo) MockMetadataManager(org.mycore.pi.MockMetadataManager) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) IntStream(java.util.stream.IntStream) Stream(java.util.stream.Stream) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Test(org.junit.Test)

Aggregations

MCRPIRegistrationInfo (org.mycore.pi.MCRPIRegistrationInfo)5 Gson (com.google.gson.Gson)2 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 MCRPIListJSON (org.mycore.pi.frontend.model.MCRPIListJSON)2 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 LinkOption (java.nio.file.LinkOption)1 Path (java.nio.file.Path)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Objects (java.util.Objects)1 TreeSet (java.util.TreeSet)1