@Test public void savePidGeneratesPersistedIdSuccessfully() throws Exception { DataSetRepository dataSetRepository = mock(DataSetRepository.class); DataSet dataSet = mock(DataSet.class); DataSetMetaData dataSetMetaData = createMockDataSetMetaData(); given(dataSet.getMetadata()).willReturn(dataSetMetaData); RdfPatchSerializer saver = createMockRdfPatchSerializer(); RdfIoFactory rdfIoFactory = createMockRdfIoFactory(saver); JsonDataStore<LogList> logListStore = new LogListJsonDataStore(); ExecutorService executor = Executors.newFixedThreadPool(10); ImportManager importManager = new ImportManager( logListStore, null, null, null, executor, rdfIoFactory, null ); given(dataSet.getImportManager()).willReturn(importManager); User user = User.create("testDisplayName", "testDataSetId"); given(dataSetRepository.getDataSet(user, "testOwnerId", "testDataSetId")) .willReturn(Optional.of(dataSet)); QueueManager queueManager = mock(QueueManager.class); QueueCreator queueCreator = new NonQueueQueueCreator(); given(queueManager.createQueue(any(),anyString())).willReturn(queueCreator); PersistenceManager persistenceManager = createMockPersistenceManager(); final HandleService handleService = new HandleService(persistenceManager, queueManager, dataSetRepository); EntityLookup entityLookup = createMockEntityLookup(user); RedirectionServiceParameters redirectionServiceParameters = new RedirectionServiceParameters( URI.create("redirectionUri"), entityLookup ); handleService.savePid(redirectionServiceParameters); verify(saver).onQuad( "testEntityUri", RdfConstants.timPredicate("persistentUri"), "testPersistentUrl", RdfConstants.STRING, null, null ); }
@Override protected void savePid(RedirectionServiceParameters params) throws PersistenceException, URISyntaxException, RedirectionServiceException { URI uri = params.getUrlToRedirectTo(); LOG.info(String.format("Retrieving persistent url for '%s'", uri)); String persistentId = (manager.persistURL(uri.toString())); URI persistentUrl = new URI(manager.getPersistentURL(persistentId)); EntityLookup entityLookup = params.getEntityLookup(); String dataSetId = entityLookup.getDataSetId().get(); Tuple<String, String> ownerIdDataSetId = DataSetMetaData.splitCombinedId(dataSetId); Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet( entityLookup.getUser().get(), ownerIdDataSetId.getLeft(), ownerIdDataSetId.getRight() ); if (!maybeDataSet.isPresent()) { throw new PersistenceException("Can't retrieve DataSet"); } DataSet dataSet = maybeDataSet.get(); final ImportManager importManager = dataSet.getImportManager(); try { importManager.generateLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), new AddTriplePatchRdfCreator( entityLookup.getUri().get(), PERSISTENT_ID, persistentUrl.toString(), RdfConstants.STRING ) ).get(); } catch (LogStorageFailedException | InterruptedException | ExecutionException e) { throw new RedirectionServiceException(e); } }
HandleService extends RedirectionService { @Override protected void savePid(RedirectionServiceParameters params) throws PersistenceException, URISyntaxException, RedirectionServiceException { URI uri = params.getUrlToRedirectTo(); LOG.info(String.format("Retrieving persistent url for '%s'", uri)); String persistentId = (manager.persistURL(uri.toString())); URI persistentUrl = new URI(manager.getPersistentURL(persistentId)); EntityLookup entityLookup = params.getEntityLookup(); String dataSetId = entityLookup.getDataSetId().get(); Tuple<String, String> ownerIdDataSetId = DataSetMetaData.splitCombinedId(dataSetId); Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet( entityLookup.getUser().get(), ownerIdDataSetId.getLeft(), ownerIdDataSetId.getRight() ); if (!maybeDataSet.isPresent()) { throw new PersistenceException("Can't retrieve DataSet"); } DataSet dataSet = maybeDataSet.get(); final ImportManager importManager = dataSet.getImportManager(); try { importManager.generateLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), new AddTriplePatchRdfCreator( entityLookup.getUri().get(), PERSISTENT_ID, persistentUrl.toString(), RdfConstants.STRING ) ).get(); } catch (LogStorageFailedException | InterruptedException | ExecutionException e) { throw new RedirectionServiceException(e); } } }
HandleService extends RedirectionService { @Override protected void savePid(RedirectionServiceParameters params) throws PersistenceException, URISyntaxException, RedirectionServiceException { URI uri = params.getUrlToRedirectTo(); LOG.info(String.format("Retrieving persistent url for '%s'", uri)); String persistentId = (manager.persistURL(uri.toString())); URI persistentUrl = new URI(manager.getPersistentURL(persistentId)); EntityLookup entityLookup = params.getEntityLookup(); String dataSetId = entityLookup.getDataSetId().get(); Tuple<String, String> ownerIdDataSetId = DataSetMetaData.splitCombinedId(dataSetId); Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet( entityLookup.getUser().get(), ownerIdDataSetId.getLeft(), ownerIdDataSetId.getRight() ); if (!maybeDataSet.isPresent()) { throw new PersistenceException("Can't retrieve DataSet"); } DataSet dataSet = maybeDataSet.get(); final ImportManager importManager = dataSet.getImportManager(); try { importManager.generateLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), new AddTriplePatchRdfCreator( entityLookup.getUri().get(), PERSISTENT_ID, persistentUrl.toString(), RdfConstants.STRING ) ).get(); } catch (LogStorageFailedException | InterruptedException | ExecutionException e) { throw new RedirectionServiceException(e); } } HandleService(PersistenceManager manager, QueueManager queueManager, DataSetRepository dataSetRepository); }
HandleService extends RedirectionService { @Override protected void savePid(RedirectionServiceParameters params) throws PersistenceException, URISyntaxException, RedirectionServiceException { URI uri = params.getUrlToRedirectTo(); LOG.info(String.format("Retrieving persistent url for '%s'", uri)); String persistentId = (manager.persistURL(uri.toString())); URI persistentUrl = new URI(manager.getPersistentURL(persistentId)); EntityLookup entityLookup = params.getEntityLookup(); String dataSetId = entityLookup.getDataSetId().get(); Tuple<String, String> ownerIdDataSetId = DataSetMetaData.splitCombinedId(dataSetId); Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet( entityLookup.getUser().get(), ownerIdDataSetId.getLeft(), ownerIdDataSetId.getRight() ); if (!maybeDataSet.isPresent()) { throw new PersistenceException("Can't retrieve DataSet"); } DataSet dataSet = maybeDataSet.get(); final ImportManager importManager = dataSet.getImportManager(); try { importManager.generateLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), new AddTriplePatchRdfCreator( entityLookup.getUri().get(), PERSISTENT_ID, persistentUrl.toString(), RdfConstants.STRING ) ).get(); } catch (LogStorageFailedException | InterruptedException | ExecutionException e) { throw new RedirectionServiceException(e); } } HandleService(PersistenceManager manager, QueueManager queueManager, DataSetRepository dataSetRepository);  }
HandleService extends RedirectionService { @Override protected void savePid(RedirectionServiceParameters params) throws PersistenceException, URISyntaxException, RedirectionServiceException { URI uri = params.getUrlToRedirectTo(); LOG.info(String.format("Retrieving persistent url for '%s'", uri)); String persistentId = (manager.persistURL(uri.toString())); URI persistentUrl = new URI(manager.getPersistentURL(persistentId)); EntityLookup entityLookup = params.getEntityLookup(); String dataSetId = entityLookup.getDataSetId().get(); Tuple<String, String> ownerIdDataSetId = DataSetMetaData.splitCombinedId(dataSetId); Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet( entityLookup.getUser().get(), ownerIdDataSetId.getLeft(), ownerIdDataSetId.getRight() ); if (!maybeDataSet.isPresent()) { throw new PersistenceException("Can't retrieve DataSet"); } DataSet dataSet = maybeDataSet.get(); final ImportManager importManager = dataSet.getImportManager(); try { importManager.generateLog( dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getGraph(), new AddTriplePatchRdfCreator( entityLookup.getUri().get(), PERSISTENT_ID, persistentUrl.toString(), RdfConstants.STRING ) ).get(); } catch (LogStorageFailedException | InterruptedException | ExecutionException e) { throw new RedirectionServiceException(e); } } HandleService(PersistenceManager manager, QueueManager queueManager, DataSetRepository dataSetRepository);  static final String HANDLE_QUEUE; }