List of usage examples for org.apache.commons.lang.mutable MutableLong getValue
public Object getValue()
From source file:eu.eubrazilcc.lvl.storage.AuthCodeCollectionTest.java
@Test public void test() { System.out.println("AuthCodeCollectionTest.test()"); try {//from ww w. ja v a 2 s . com // insert final AuthCode authCode = AuthCode.builder().code("1234567890abcdEFGhiJKlMnOpqrstUVWxyZ") .issuedAt(System.currentTimeMillis() / 1000l).expiresIn(23l).build(); AUTH_CODE_DAO.insert(authCode); // find AuthCode authCode2 = AUTH_CODE_DAO.find(authCode.getCode()); assertThat("authorization code is not null", authCode2, notNullValue()); assertThat("authorization code coincides with original", authCode2, equalTo(authCode)); System.out.println(authCode2.toString()); // update authCode.setExpiresIn(3600l); AUTH_CODE_DAO.update(authCode); // find after update authCode2 = AUTH_CODE_DAO.find(authCode.getCode()); assertThat("authorization code is not null", authCode2, notNullValue()); assertThat("authorization code coincides with original", authCode2, equalTo(authCode)); System.out.println(authCode2.toString()); // check validity final boolean validity = AUTH_CODE_DAO.isValid(authCode.getCode()); assertThat("authorization code is valid", validity); // remove AUTH_CODE_DAO.delete(authCode.getCode()); final long numRecords = AUTH_CODE_DAO.count(); assertThat("number of authorization codes stored in the database coincides with expected", numRecords, equalTo(0l)); // pagination final List<String> ids = newArrayList(); for (int i = 0; i < 11; i++) { final AuthCode authCode3 = AuthCode.builder().code(Integer.toString(i)).build(); ids.add(authCode3.getCode()); AUTH_CODE_DAO.insert(authCode3); } final int size = 3; int start = 0; List<AuthCode> authCodes = null; final MutableLong count = new MutableLong(0l); do { authCodes = AUTH_CODE_DAO.list(start, size, null, null, null, count); if (authCodes.size() != 0) { System.out.println("Paging: first item " + start + ", showing " + authCodes.size() + " of " + count.getValue() + " items"); } start += authCodes.size(); } while (!authCodes.isEmpty()); for (final String id2 : ids) { AUTH_CODE_DAO.delete(id2); } AUTH_CODE_DAO.stats(System.out); } catch (Exception e) { e.printStackTrace(System.err); fail("AuthCodeCollectionTest.test() failed: " + e.getMessage()); } finally { System.out.println("AuthCodeCollectionTest.test() has finished"); } }
From source file:eu.eubrazilcc.lvl.storage.WorkflowRunCollectionTest.java
@Test public void test() { System.out.println("WorkflowRunCollectionTest.test()"); try {//w w w . java 2 s .co m // insert final WorkflowRun run = WorkflowRun.builder().id("ABCD123").workflowId("980TYHN1").invocationId("1209") .parameters(WorkflowParameters.builder().parameter("var1", "1", null, null) .parameter("var2", "2", null, null).build()) .submitter("submitter").submitted(new Date()).build(); WORKFLOW_RUN_DAO.insert(run); // find WorkflowRun run2 = WORKFLOW_RUN_DAO.find(run.getId()); assertThat("workflow run is not null", run2, notNullValue()); assertThat("workflow run coincides with original", run2, equalTo(run)); System.out.println(run2.toString()); // update run.setSubmitter("submitter2"); WORKFLOW_RUN_DAO.update(run); // find after update run2 = WORKFLOW_RUN_DAO.find(run.getId()); assertThat("workflow run is not null", run2, notNullValue()); assertThat("workflow run coincides with original", run2, equalTo(run)); System.out.println(run2.toString()); // list all by submitter List<WorkflowRun> runs = WORKFLOW_RUN_DAO.findAll(run.getSubmitter()); assertThat("workflow runs are not null", runs, notNullValue()); assertThat("workflow runs are not empty", !runs.isEmpty(), equalTo(true)); assertThat("number of workflow runs coincides with expected", runs.size(), equalTo(1)); assertThat("workflow runs coincide with original", runs.get(0), equalTo(run)); // remove WORKFLOW_RUN_DAO.delete(run.getId()); final long numRecords = WORKFLOW_RUN_DAO.count(); assertThat("number of workflow runs stored in the database coincides with expected", numRecords, equalTo(0l)); // pagination final List<String> ids = newArrayList(); for (int i = 0; i < 11; i++) { final WorkflowRun run3 = WorkflowRun.builder().id(Integer.toString(i)).build(); ids.add(run3.getId()); WORKFLOW_RUN_DAO.insert(run3); } final int size = 3; int start = 0; runs = null; final MutableLong count = new MutableLong(0l); do { runs = WORKFLOW_RUN_DAO.list(start, size, null, null, null, count); if (runs.size() != 0) { System.out.println("Paging: first item " + start + ", showing " + runs.size() + " of " + count.getValue() + " items"); } start += runs.size(); } while (!runs.isEmpty()); for (final String id2 : ids) { WORKFLOW_RUN_DAO.delete(id2); } WORKFLOW_RUN_DAO.stats(System.out); } catch (Exception e) { e.printStackTrace(System.err); fail("WorkflowRunCollectionTest.test() failed: " + e.getMessage()); } finally { System.out.println("WorkflowRunCollectionTest.test() has finished"); } }
From source file:eu.eubrazilcc.lvl.storage.ClientAppCollectionTest.java
@Test public void test() { System.out.println("ClientAppCollectionTest.test()"); try {//w ww.ja v a2 s .co m // insert final ClientApp clientApp = ClientApp.builder().name("client_name").url("http://localhost/client") .description("Sample client").icon("http://localhost/client/icon") .redirectURL("http://localhost/client/redirect") .clientId(NamingUtils.toAsciiSafeName("client_name")) .clientSecret("1234567890abcdEFGhiJKlMnOpqrstUVWxyZ").issuedAt(1000l).expiresIn(2000l).build(); CLIENT_APP_DAO.insert(clientApp); // find ClientApp clientApp2 = CLIENT_APP_DAO.find(clientApp.getClientId()); assertThat("client application is not null", clientApp2, notNullValue()); assertThat("client application coincides with original", clientApp2, equalTo(clientApp)); System.out.println(clientApp2.toString()); // update clientApp.setExpiresIn(4000l); CLIENT_APP_DAO.update(clientApp); // check validity boolean validity = CLIENT_APP_DAO.isValid(clientApp.getClientId()); assertThat("client application is valid (secret excluded)", validity); validity = CLIENT_APP_DAO.isValid(clientApp.getClientId(), clientApp.getClientSecret()); assertThat("client application is valid (secret included)", validity); // find after update clientApp2 = CLIENT_APP_DAO.find(clientApp.getClientId()); assertThat("client application is not null", clientApp2, notNullValue()); assertThat("client application coincides with original", clientApp2, equalTo(clientApp)); System.out.println(clientApp2.toString()); // remove (default LVL application is not removed) CLIENT_APP_DAO.delete(clientApp.getClientId()); final long numRecords = CLIENT_APP_DAO.count(); assertThat("number of client applications stored in the database coincides with expected", numRecords, equalTo(1l)); // pagination final List<String> ids = newArrayList(); for (int i = 0; i < 11; i++) { final ClientApp clientApp3 = ClientApp.builder().name(Integer.toString(i)) .url("http://localhost/client").description("Sample client") .icon("http://localhost/client/icon").redirectURL("http://localhost/client/redirect") .clientId(NamingUtils.toAsciiSafeName((Integer.toString(i)))) .clientSecret("1234567890abcdEFGhiJKlMnOpqrstUVWxyZ").issuedAt(1000l).expiresIn(2000l) .build(); ids.add(clientApp3.getClientId()); CLIENT_APP_DAO.insert(clientApp3); } final int size = 3; int start = 0; List<ClientApp> clientApps = null; final MutableLong count = new MutableLong(0l); do { clientApps = CLIENT_APP_DAO.list(start, size, null, null, null, count); if (clientApps.size() != 0) { System.out.println("Paging: first item " + start + ", showing " + clientApps.size() + " of " + count.getValue() + " items"); } start += clientApps.size(); } while (!clientApps.isEmpty()); for (final String id2 : ids) { CLIENT_APP_DAO.delete(id2); } CLIENT_APP_DAO.stats(System.out); } catch (Exception e) { e.printStackTrace(System.err); fail("ClientAppCollectionTest.test() failed: " + e.getMessage()); } finally { System.out.println("ClientAppCollectionTest.test() has finished"); } }
From source file:eu.eubrazilcc.lvl.storage.LinkedInStateCollectionTest.java
@Test public void test() { System.out.println("LinkedInStateCollectionTest.test()"); try {/*from ww w.j a v a 2 s .c o m*/ // insert final long issuedAt = currentTimeMillis() / 1000l; final LinkedInState state = LinkedInState.builder().state("1234567890abcdEFGhiJKlMnOpqrstUVWxyZ") .issuedAt(issuedAt).expiresIn(23l).redirectUri("http://localhost/redirect") .callback("http://localhost/callback").build(); LINKEDIN_STATE_DAO.insert(state); // find LinkedInState state2 = LINKEDIN_STATE_DAO.find(state.getState()); assertThat("linkedin state is not null", state2, notNullValue()); assertThat("linkedin state coincides with original", state2, equalTo(state)); System.out.println(state2.toString()); // update state.setExpiresIn(604800l); LINKEDIN_STATE_DAO.update(state); // find after update state2 = LINKEDIN_STATE_DAO.find(state.getState()); assertThat("linkedin state is not null", state2, notNullValue()); assertThat("linkedin state coincides with original", state2, equalTo(state)); System.out.println(state2.toString()); // list by issued date List<LinkedInState> states = LINKEDIN_STATE_DAO.listByIssuedDate(new Date(issuedAt)); assertThat("linkedin states are not null", states, notNullValue()); assertThat("linkedin states are not empty", !states.isEmpty(), equalTo(true)); assertThat("number of linkedin states coincides with expected", states.size(), equalTo(1)); assertThat("linkedin states coincide with original", states.get(0), equalTo(state)); // check validity final AtomicReference<String> redirectUriRef = new AtomicReference<String>(); final AtomicReference<String> callbackRef = new AtomicReference<String>(); boolean validity = LINKEDIN_STATE_DAO.isValid(state.getState(), redirectUriRef, callbackRef); assertThat("linkedin state is valid", validity, equalTo(true)); assertThat("linkedin redirect URI is not null", redirectUriRef.get(), notNullValue()); assertThat("linkedin redirect URI coincides with expected", redirectUriRef.get(), equalTo("http://localhost/redirect")); assertThat("linkedin callback URI is not null", callbackRef.get(), notNullValue()); assertThat("linkedin callback URI coincides with expected", callbackRef.get(), equalTo("http://localhost/callback")); // remove LINKEDIN_STATE_DAO.delete(state.getState()); final long numRecords = LINKEDIN_STATE_DAO.count(); assertThat("number of linkedin states stored in the database coincides with expected", numRecords, equalTo(0l)); // pagination final List<String> ids = newArrayList(); for (int i = 0; i < 11; i++) { final LinkedInState state3 = LinkedInState.builder().state(Integer.toString(i)).build(); ids.add(state3.getState()); LINKEDIN_STATE_DAO.insert(state3); } final int size = 3; int start = 0; states = null; final MutableLong count = new MutableLong(0l); do { states = LINKEDIN_STATE_DAO.list(start, size, null, null, null, count); if (states.size() != 0) { System.out.println("Paging: first item " + start + ", showing " + states.size() + " of " + count.getValue() + " items"); } start += states.size(); } while (!states.isEmpty()); for (final String id2 : ids) { LINKEDIN_STATE_DAO.delete(id2); } LINKEDIN_STATE_DAO.stats(System.out); } catch (Exception e) { e.printStackTrace(System.err); fail("LinkedInStateCollectionTest.test() failed: " + e.getMessage()); } finally { System.out.println("LinkedInStateCollectionTest.test() has finished"); } }
From source file:eu.eubrazilcc.lvl.storage.TokenCollectionTest.java
@Test public void test() { System.out.println("TokenCollectionTest.test()"); try {/*from w w w . j a v a2s. c o m*/ final Collection<String> scopes = newArrayList("scope1", "scope2", "scope2/username1", "scope3,a"); // insert final AccessToken accessToken = AccessToken.builder().token("1234567890abcdEFGhiJKlMnOpqrstUVWxyZ") .issuedAt(currentTimeMillis() / 1000l).expiresIn(23l).ownerId("username1").scope(scopes) .build(); TOKEN_DAO.insert(accessToken); // find AccessToken accessToken2 = TOKEN_DAO.find(accessToken.getToken()); assertThat("access token is not null", accessToken2, notNullValue()); assertThat("access token coincides with original", accessToken2, equalTo(accessToken)); System.out.println(accessToken2.toString()); // update accessToken.setExpiresIn(604800l); TOKEN_DAO.update(accessToken); // find after update accessToken2 = TOKEN_DAO.find(accessToken.getToken()); assertThat("access token is not null", accessToken2, notNullValue()); assertThat("access token coincides with original", accessToken2, equalTo(accessToken)); System.out.println(accessToken2.toString()); // list by owner Id List<AccessToken> accessTokens = TOKEN_DAO.listByOwnerId(accessToken.getOwnerId()); assertThat("access tokens are not null", accessTokens, notNullValue()); assertThat("access tokens are not empty", !accessTokens.isEmpty(), equalTo(true)); assertThat("number of access tokens coincides with expected", accessTokens.size(), equalTo(1)); assertThat("access tokens coincide with original", accessTokens.get(0), equalTo(accessToken)); // check validity boolean validity = TOKEN_DAO.isValid(accessToken.getToken()); assertThat("access token is valid", validity, equalTo(true)); final AtomicReference<String> ownerIdRef = new AtomicReference<String>(); validity = TOKEN_DAO.isValid(accessToken.getToken(), ownerIdRef); assertThat("access token is valid using target scope", validity, equalTo(true)); assertThat("owner id coincides is not null", ownerIdRef.get(), notNullValue()); assertThat("owner id coincides with expected", ownerIdRef.get(), equalTo(accessToken.getOwnerId())); // remove TOKEN_DAO.delete(accessToken.getToken()); final long numRecords = TOKEN_DAO.count(); assertThat("number of access tokens stored in the database coincides with expected", numRecords, equalTo(0l)); // pagination final List<String> ids = newArrayList(); for (int i = 0; i < 11; i++) { final AccessToken accessToken3 = AccessToken.builder().token(Integer.toString(i)).build(); ids.add(accessToken3.getToken()); TOKEN_DAO.insert(accessToken3); } final int size = 3; int start = 0; accessTokens = null; final MutableLong count = new MutableLong(0l); do { accessTokens = TOKEN_DAO.list(start, size, null, null, null, count); if (accessTokens.size() != 0) { System.out.println("Paging: first item " + start + ", showing " + accessTokens.size() + " of " + count.getValue() + " items"); } start += accessTokens.size(); } while (!accessTokens.isEmpty()); for (final String id2 : ids) { TOKEN_DAO.delete(id2); } TOKEN_DAO.stats(System.out); } catch (Exception e) { e.printStackTrace(System.err); fail("TokenCollectionTest.test() failed: " + e.getMessage()); } finally { System.out.println("TokenCollectionTest.test() has finished"); } }
From source file:eu.eubrazilcc.lvl.storage.LvlInstanceCollectionTest.java
@Test public void test() { System.out.println("LvlInstanceCollectionTest.test()"); try {// w ww. jav a 2 s .c o m // insert final Date heartbeat = new Date(); final LvlInstance instance = LvlInstance.builder().instanceId("instanceId").roles(newHashSet("shard")) .heartbeat(heartbeat).location(Point.builder() .coordinates(LngLatAlt.builder().coordinates(1.0d, 2.0d).build()).build()) .build(); WriteResult<LvlInstance> writeResult = INSTANCE_DAO.insert(instance); assertThat("insert write result is not null", writeResult, notNullValue()); assertThat("insert write result Id is not null", writeResult.getId(), notNullValue()); assertThat("insert write result Id is not empty", isNotBlank(writeResult.getId()), equalTo(true)); final String dbId = writeResult.getId(); // insert ignoring duplicates writeResult = INSTANCE_DAO.insert(instance, true); assertThat("insert write result is not null after duplicate insertion", writeResult, notNullValue()); assertThat("insert write result Id is not null after duplicate insertion", writeResult.getId(), notNullValue()); assertThat("insert write result Id is not empty after duplicate insertion", isNotBlank(writeResult.getId()), equalTo(true)); assertThat("insert write result Id coincides with expected after duplicate insertion", writeResult.getId(), equalTo(dbId)); try { INSTANCE_DAO.insert(instance, false); fail("Expected Exception due to duplicate insertion"); } catch (RuntimeException expected) { System.out.println("Expected exception caught: " + expected.getClass()); } // find LvlInstance instance2 = INSTANCE_DAO.find(instance.getInstanceId()); assertThat("instance is not null", instance2, notNullValue()); assertThat("instance coincides with original", instance2, equalTo(instance)); System.out.println(instance2.toString()); // list with projection List<LvlInstance> instances = INSTANCE_DAO.list(0, Integer.MAX_VALUE, null, null, ImmutableMap.of(GEOLOCATION_KEY, false), null); assertThat("projected instances is not null", instances, notNullValue()); assertThat("number of projected instances coincides with expected", instances.size(), equalTo(1)); assertThat("location was filtered from database response", instances.get(0).getLocation(), nullValue()); // update instance.setRoles(newHashSet("working_node")); INSTANCE_DAO.update(instance); // find after update instance2 = INSTANCE_DAO.find(instance.getInstanceId()); assertThat("instance is not null", instance2, notNullValue()); assertThat("instance coincides with original", instance2, equalTo(instance)); System.out.println(instance2.toString()); // remove INSTANCE_DAO.delete(instance.getInstanceId()); final long numRecords = INSTANCE_DAO.count(); assertThat("number of instances stored in the database coincides with expected", numRecords, equalTo(0l)); // pagination final List<String> ids = newArrayList(); for (int i = 0; i < 11; i++) { final LvlInstance instance3 = LvlInstance.builder().instanceId("Instance " + i).build(); ids.add(instance3.getInstanceId()); INSTANCE_DAO.insert(instance3); } final int size = 3; int start = 0; instances = null; final MutableLong count = new MutableLong(0l); do { instances = INSTANCE_DAO.list(start, size, null, null, null, count); if (instances.size() != 0) { System.out.println("Paging: first item " + start + ", showing " + instances.size() + " of " + count.getValue() + " items"); } start += instances.size(); } while (!instances.isEmpty()); for (final String id2 : ids) { INSTANCE_DAO.delete(id2); } INSTANCE_DAO.stats(System.out); } catch (Exception e) { e.printStackTrace(System.err); fail("LvlInstanceCollectionTest.test() failed: " + e.getMessage()); } finally { System.out.println("LvlInstanceCollectionTest.test() has finished"); } }
From source file:eu.eubrazilcc.lvl.storage.ReferenceCollectionTest.java
@Test public void test() { System.out.println("ReferenceCollectionTest.test()"); try {// w ww .j a v a 2 s .c o m // create article citation final PubmedArticle article = PUBMED_XML_FACTORY.createPubmedArticle() .withMedlineCitation(PUBMED_XML_FACTORY.createMedlineCitation().withArticle( PUBMED_XML_FACTORY.createArticle().withArticleTitle("The best paper in the world"))) .withMedlineCitation(PUBMED_XML_FACTORY.createMedlineCitation() .withPMID(PUBMED_XML_FACTORY.createPMID().withvalue("ABCD1234"))); // insert final Reference reference = Reference.builder().title("The best paper in the world") .pubmedId("ABCD1234").publicationYear(1984).seqids(newHashSet("gb:ABC12345678")) .article(article).build(); WriteResult<Reference> writeResult = REFERENCE_DAO.insert(reference); assertThat("insert write result is not null", writeResult, notNullValue()); assertThat("insert write result Id is not null", writeResult.getId(), notNullValue()); assertThat("insert write result Id is not empty", isNotBlank(writeResult.getId()), equalTo(true)); final String dbId = writeResult.getId(); // insert ignoring duplicates writeResult = REFERENCE_DAO.insert(reference, true); assertThat("insert write result is not null after duplicate insertion", writeResult, notNullValue()); assertThat("insert write result Id is not null after duplicate insertion", writeResult.getId(), notNullValue()); assertThat("insert write result Id is not empty after duplicate insertion", isNotBlank(writeResult.getId()), equalTo(true)); assertThat("insert write result Id coincides with expected after duplicate insertion", writeResult.getId(), equalTo(dbId)); try { REFERENCE_DAO.insert(reference, false); fail("Expected Exception due to duplicate insertion"); } catch (RuntimeException expected) { System.out.println("Expected exception caught: " + expected.getClass()); } // find Reference reference2 = REFERENCE_DAO.find(reference.getPubmedId()); assertThat("reference is not null", reference2, notNullValue()); assertThat("reference coincides with original", reference2, equalTo(reference)); assertThat("reference contains original sequence", reference2.getArticle(), notNullValue()); System.out.println(reference2.toString()); // list with projection List<Reference> references = REFERENCE_DAO.list(0, Integer.MAX_VALUE, null, null, ImmutableMap.of(ORIGINAL_ARTICLE_KEY, false), null); assertThat("projected references is not null", references, notNullValue()); assertThat("number of projected references coincides with expected", references.size(), equalTo(1)); assertThat("article was filtered from database response", references.get(0).getArticle(), nullValue()); // update reference.setTitle("The second best paper in the world"); REFERENCE_DAO.update(reference); // find after update reference2 = REFERENCE_DAO.find(reference.getPubmedId()); assertThat("reference is not null", reference2, notNullValue()); assertThat("reference coincides with original", reference2, equalTo(reference)); System.out.println(reference2.toString()); // remove REFERENCE_DAO.delete(reference.getPubmedId()); final long numRecords = REFERENCE_DAO.count(); assertThat("number of references stored in the database coincides with expected", numRecords, equalTo(0l)); // pagination final List<String> ids = newArrayList(); for (int i = 0; i < 11; i++) { final PubmedArticle article3 = PUBMED_XML_FACTORY.createPubmedArticle() .withMedlineCitation(PUBMED_XML_FACTORY.createMedlineCitation().withArticle( PUBMED_XML_FACTORY.createArticle().withArticleTitle("Paper number " + i))) .withMedlineCitation(PUBMED_XML_FACTORY.createMedlineCitation() .withPMID(PUBMED_XML_FACTORY.createPMID().withvalue(Integer.toString(i)))); final Reference reference3 = Reference.builder().title("Paper number " + i) .pubmedId(Integer.toString(i)).article(article3).build(); ids.add(reference3.getPubmedId()); REFERENCE_DAO.insert(reference3); } final int size = 3; int start = 0; references = null; final MutableLong count = new MutableLong(0l); do { references = REFERENCE_DAO.list(start, size, null, null, null, count); if (references.size() != 0) { System.out.println("Paging: first item " + start + ", showing " + references.size() + " of " + count.getValue() + " items"); } start += references.size(); } while (!references.isEmpty()); for (final String id2 : ids) { REFERENCE_DAO.delete(id2); } REFERENCE_DAO.stats(System.out); } catch (Exception e) { e.printStackTrace(System.err); fail("ReferenceCollectionTest.test() failed: " + e.getMessage()); } finally { System.out.println("ReferenceCollectionTest.test() has finished"); } }
From source file:eu.eubrazilcc.lvl.service.rest.DatasetShareResource.java
@GET @Path("{namespace: " + URL_FRAGMENT_PATTERN + "}/{filename: " + URL_FRAGMENT_PATTERN + "}") @Produces(APPLICATION_JSON)/*from w w w . ja v a 2 s. c om*/ public DatasetShares getDatasetShares(final @PathParam("namespace") String namespace, final @PathParam("filename") String filename, final @QueryParam("page") @DefaultValue("0") int page, final @QueryParam("per_page") @DefaultValue("100") int per_page, final @Context UriInfo uriInfo, final @Context HttpServletRequest request, final @Context HttpHeaders headers) { final String namespace2 = parseParam(namespace), filename2 = parseParam(filename); final String ownerid = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME) .requiresPermissions("datasets:files:" + ns2permission(namespace2) + ":" + filename2 + ":view") .getPrincipal(); final DatasetShares paginable = DatasetShares.start().page(page).perPage(per_page).build(); // get datasets from database final MutableLong count = new MutableLong(0l); final List<DatasetShare> datashares = RESOURCE_OWNER_DAO.listDatashares(ns2dbnamespace(namespace2, ownerid), filename2, paginable.getPageFirstEntry(), per_page, null, null, count); paginable.setElements(datashares); // set total count and return to the caller final int totalEntries = ((Long) count.getValue()).intValue(); paginable.setTotalCount(totalEntries); return paginable; }
From source file:eu.eubrazilcc.lvl.service.rest.DatasetResource.java
@GET @Path("{namespace: " + URL_FRAGMENT_PATTERN + "}") @Produces(APPLICATION_JSON)/*from w w w. j a va 2 s . c o m*/ public Datasets getDatasets(final @PathParam("namespace") String namespace, final @QueryParam("page") @DefaultValue("0") int page, final @QueryParam("per_page") @DefaultValue("100") int per_page, final @Context UriInfo uriInfo, final @Context HttpServletRequest request, final @Context HttpHeaders headers) { final String namespace2 = parseParam(namespace); final OAuth2SecurityManager securityManager = OAuth2SecurityManager .login(request, null, headers, RESOURCE_NAME) .requiresPermissions("datasets:files:" + ns2permission(namespace2) + ":*:view"); final String ownerid = securityManager.getPrincipal(); final Datasets paginable = Datasets.start().page(page).perPage(per_page).build(); // get datasets from database final MutableLong count = new MutableLong(0l); final List<Dataset> datasets = DATASET_DAO.list(ns2dbnamespace(namespace2, ownerid), paginable.getPageFirstEntry(), per_page, null, null, count); paginable.setElements(datasets); // set total count and return to the caller final int totalEntries = ((Long) count.getValue()).intValue(); paginable.setTotalCount(totalEntries); return paginable; }
From source file:eu.eubrazilcc.lvl.storage.NotificationCollectionTest.java
@Test public void test() { System.out.println("NotificationCollectionTest.test()"); try {/*from w w w . j av a 2s . com*/ // insert final Notification notification = Notification.builder().message("This is an example").build(); final String id = NOTIFICATION_DAO.insert(notification).getId(); assertThat("notification id is not null", id, notNullValue()); assertThat("notification id is not empty", isNotBlank(id)); notification.setId(id); // find Notification notification2 = NOTIFICATION_DAO.find(notification.getId()); assertThat("notification is not null", notification2, notNullValue()); assertThat("notification coincides with original", notification2, equalTo(notification)); System.out.println(notification2.toString()); // update notification.setAction(new Action("/#/action", "This is an action")); notification.setPriority(Priority.HIGH); NOTIFICATION_DAO.update(notification); // find after update notification2 = NOTIFICATION_DAO.find(notification.getId()); assertThat("notification is not null", notification2, notNullValue()); assertThat("notification coincides with original", notification2, equalTo(notification)); System.out.println(notification2.toString()); // remove NOTIFICATION_DAO.delete(notification.getId()); final long numRecords = NOTIFICATION_DAO.count(); assertThat("number of notifications stored in the database coincides with expected", numRecords, equalTo(0l)); // create a large dataset to test complex operations final List<String> ids = newArrayList(); final int numItems = 11; for (int i = 0; i < numItems; i++) { final Notification notification3 = Notification.builder().message(Integer.toString(i)).build(); ids.add(NOTIFICATION_DAO.insert(notification3).getId()); } // pagination final int size = 3; int start = 0; List<Notification> notifications = null; final MutableLong count = new MutableLong(0l); do { notifications = NOTIFICATION_DAO.list(start, size, null, null, null, count); if (notifications.size() != 0) { System.out.println("Paging: first item " + start + ", showing " + notifications.size() + " of " + count.getValue() + " items"); } start += notifications.size(); } while (!notifications.isEmpty()); // clean-up and display database statistics for (final String id2 : ids) { NOTIFICATION_DAO.delete(id2); } NOTIFICATION_DAO.stats(System.out); // test notification sending final List<Notification> notifications2 = newArrayList(); for (int i = 0; i < 200; i++) { Priority priority; if (i < 50) { priority = Priority.CRITICAL; } else if (i >= 50 && i < 100) { priority = Priority.HIGH; } else if (i >= 100 && i < 150) { priority = Priority.NORMAL; } else { priority = Priority.LOW; } final Notification notification3 = Notification.builder().priority(priority).addressee(ADMIN_USER) .message(Integer.toString(i)).build(); notifications2.add(notification3); } shuffle(notifications2); for (final Notification notification3 : notifications2) { NOTIFICATION_MANAGER.send(notification3); } int tries = 0; while (NOTIFICATION_MANAGER.hasPendingNotifications() && tries++ < 30) { Thread.sleep(1000l); } notifications = NOTIFICATION_DAO.list(0, 200, null, null, null, null); assertThat("notifications is not null", notifications, notNullValue()); assertThat("notifications size coincides with expected", notifications.size(), equalTo(200)); // test notification broadcasting final Notification notification3 = Notification.builder().scope(ADMIN_ROLE) .message("Notification to all users granted with full access to the system").build(); NOTIFICATION_MANAGER.broadcast(notification3); tries = 0; while (NOTIFICATION_MANAGER.hasPendingNotifications() && tries++ < 30) { Thread.sleep(1000l); } notifications = NOTIFICATION_DAO.list(0, 201, null, null, null, null); assertThat("notifications (including broadcasted) is not null", notifications, notNullValue()); assertThat("notifications (including broadcasted) size coincides with expected", notifications.size(), equalTo(201)); } catch (Exception e) { e.printStackTrace(System.err); fail("NotificationCollectionTest.test() failed: " + e.getMessage()); } finally { System.out.println("NotificationCollectionTest.test() has finished"); } }