List of usage examples for java.util Date toInstant
public Instant toInstant()
From source file:com.ikanow.aleph2.analytics.services.TestDeduplicationService.java
@Test public void test_timestamps() { final Date d = new Date(0L); final Date d2 = new Date(); final TimeTestBean bean1 = new TimeTestBean(d, d.getTime(), null, "banana"); //(old) final JsonNode json1 = BeanTemplateUtils.toJson(bean1); final TimeTestBean bean2 = new TimeTestBean(d2, null, d.toInstant().toString(), null); //(new) final JsonNode json2 = BeanTemplateUtils.toJson(bean2); // Check some very basic time utils {//from ww w. j ava2s.c om assertEquals(0L, DeduplicationService.getTimestampFromJsonNode(json1.get("d")).get().longValue()); assertEquals(0L, DeduplicationService.getTimestampFromJsonNode(json1.get("l")).get().longValue()); assertEquals(0L, DeduplicationService.getTimestampFromJsonNode(json2.get("s")).get().longValue()); assertEquals(Optional.empty(), DeduplicationService.getTimestampFromJsonNode(json1.get("err"))); ; assertEquals(Optional.empty(), DeduplicationService.getTimestampFromJsonNode(json2.get("err"))); ; assertEquals(Optional.empty(), DeduplicationService.getTimestampFromJsonNode(_mapper.createObjectNode())); //(code coverage!) } // Compare sets of 2 json objects { assertTrue(DeduplicationService.newRecordUpdatesOld("d", json2, json1)); assertFalse(DeduplicationService.newRecordUpdatesOld("d", json1, json2)); assertFalse(DeduplicationService.newRecordUpdatesOld("d", json1, json1)); // (new doesn't have field so always false) assertFalse(DeduplicationService.newRecordUpdatesOld("l", json2, json1)); assertFalse(DeduplicationService.newRecordUpdatesOld("l", json1, json2)); assertFalse(DeduplicationService.newRecordUpdatesOld("l", json1, json1)); // (old doesn't have field so always false) assertFalse(DeduplicationService.newRecordUpdatesOld("s", json2, json1)); assertFalse(DeduplicationService.newRecordUpdatesOld("s", json1, json2)); assertFalse(DeduplicationService.newRecordUpdatesOld("s", json1, json1)); } }
From source file:org.nuxeo.ecm.core.TestSQLRepositoryQuery.java
@Test public void testQueryACL() throws Exception { createDocs();/*from www .j av a 2s .c om*/ DocumentModel folder1 = session.getDocument(new PathRef("/testfolder1")); ACP acp = new ACPImpl(); ACL acl = new ACLImpl(); acl.add(new ACE("Administrator", "Everything", true)); acl.add(new ACE("bob", "Browse", true)); acl.add(new ACE("steve", "Read", true)); Date now = new Date(); Calendar begin = new GregorianCalendar(); begin.setTimeInMillis(now.toInstant().minus(5, ChronoUnit.DAYS).toEpochMilli()); Calendar end = new GregorianCalendar(); end.setTimeInMillis(now.toInstant().plus(5, ChronoUnit.DAYS).toEpochMilli()); acl.add(ACE.builder("leela", "Write").creator("Administrator").begin(begin).end(end).build()); acl.add(ACE.BLOCK); acp.addACL(acl); folder1.setACP(acp, true); session.save(); String queryBase = "SELECT * FROM Document WHERE ecm:isProxy = 0 AND "; // simple query checkQueryACL(1, queryBase + "ecm:acl/*/principal = 'bob'"); // documents with both bob and steve checkQueryACL(1, queryBase + "ecm:acl/*/principal = 'bob' AND ecm:acl/*/principal = 'steve'"); // bob cannot be steve, no match checkQueryACL(0, queryBase + "ecm:acl/*1/principal = 'bob' AND ecm:acl/*1/principal = 'steve'"); // bob with Browse checkQueryACL(1, queryBase + "ecm:acl/*1/principal = 'bob' AND ecm:acl/*1/permission = 'Browse'"); // bob with Browse granted checkQueryACL(1, queryBase + "ecm:acl/*1/principal = 'bob' AND ecm:acl/*1/permission = 'Browse' AND ecm:acl/*1/grant = 1"); // bob with Browse denied, no match checkQueryACL(0, queryBase + "ecm:acl/*1/principal = 'bob' AND ecm:acl/*1/permission = 'Browse' AND ecm:acl/*1/grant = 0"); // bob with Read, no match checkQueryACL(0, queryBase + "ecm:acl/*1/principal = 'bob' AND ecm:acl/*1/permission = 'Read'"); // a bob and a Read checkQueryACL(1, queryBase + "ecm:acl/*/principal = 'bob' AND ecm:acl/*/permission = 'Read'"); // creator is Administrator checkQueryACL(1, queryBase + "ecm:acl/*/creator = 'Administrator'"); // document for leela with a begin date after 2007-01-01 checkQueryACL(1, queryBase + "ecm:acl/*1/principal = 'leela' AND ecm:acl/*1/begin >= DATE '2007-01-01' AND ecm:acl/*1/end <= DATE '2020-01-01'"); // document for leela with an end date after 2020-01-01, no match checkQueryACL(0, queryBase + "ecm:acl/*1/principal = 'leela' AND ecm:acl/*1/end >= DATE '2020-01-01'"); // document with valid begin date but not end date, no match checkQueryACL(0, queryBase + "ecm:acl/*1/begin >= DATE '2007-01-01' AND ecm:acl/*1/end >= DATE '2020-01-01'"); // document with effective acl checkQueryACL(1, queryBase + "ecm:acl/*1/status = 1"); if (!notMatchesNull()) { // document with pending or archived acl, no match checkQueryACL(0, queryBase + "ecm:acl/*1/status <> 1"); } // block checkQueryACL(1, queryBase + "ecm:acl/*1/principal = 'Everyone' AND ecm:acl/*1/permission = 'Everything' AND ecm:acl/*1/grant = 0"); if (!isDBS()) { // explicit array index checkQueryACL(1, queryBase + "ecm:acl/1/principal = 'bob'"); } }
From source file:org.nuxeo.ecm.core.TestSQLRepositoryQuery.java
@Test public void testQueryACLReturnedValue() throws Exception { createDocs();/*from w w w . ja va2 s . c o m*/ DocumentModel folder1 = session.getDocument(new PathRef("/testfolder1")); ACP acp = new ACPImpl(); ACL acl = new ACLImpl(); acl.add(new ACE("Administrator", "Everything", true)); acl.add(new ACE("bob", "Browse", true)); acl.add(new ACE("steve", "Read", true)); Date now = new Date(); Calendar begin = new GregorianCalendar(); begin.setTimeInMillis(now.toInstant().minus(5, ChronoUnit.DAYS).toEpochMilli()); // avoid DB rounding for timestamp on seconds / milliseconds begin.set(Calendar.SECOND, 0); begin.set(Calendar.MILLISECOND, 0); Calendar end = new GregorianCalendar(); end.setTimeInMillis(now.toInstant().plus(5, ChronoUnit.DAYS).toEpochMilli()); end.set(Calendar.SECOND, 0); end.set(Calendar.MILLISECOND, 0); acl.add(ACE.builder("leela", "Write").creator("Administrator").begin(begin).end(end).build()); acl.add(ACE.BLOCK); acp.addACL(acl); folder1.setACP(acp, true); session.save(); // update the begin and end dates from the one being stored in the DB to correctly match them after ACP updatedACP = session.getACP(folder1.getRef()); ACL updatedACL = updatedACP.getACL(ACL.LOCAL_ACL); for (ACE ace : updatedACL) { if ("leela".equals(ace.getUsername())) { begin = ace.getBegin(); end = ace.getEnd(); break; } } IterableQueryResult res; // simple query res = session.queryAndFetch( "SELECT ecm:uuid, ecm:acl/*1/name, ecm:acl/*1/principal, ecm:acl/*1/permission FROM Document WHERE ecm:isProxy = 0 AND " + "ecm:acl/*1/permission in ('Read', 'Browse') AND ecm:acl/*1/grant = 1", "NXQL"); assertEquals(2, res.size()); Set<String> set = new HashSet<>(); for (Map<String, Serializable> map : res) { set.add(map.get("ecm:acl/*1/name") + ":" + map.get("ecm:acl/*1/principal") + ":" + map.get("ecm:acl/*1/permission")); } res.close(); assertEquals(new HashSet<>(Arrays.asList("local:bob:Browse", "local:steve:Read")), set); // read full ACL // ecm:pos in VCS-specific so not checked res = session.queryAndFetch( "SELECT ecm:uuid, ecm:acl/*1/name, ecm:acl/*1/principal, ecm:acl/*1/permission, ecm:acl/*1/grant" + ", ecm:acl/*1/creator, ecm:acl/*1/begin, ecm:acl/*1/end FROM Document" + " WHERE ecm:isProxy = 0 AND " + "ecm:acl/*/principal = 'bob'", "NXQL"); assertEquals(5, res.size()); set = new HashSet<>(); for (Map<String, Serializable> map : res) { String ace = map.get("ecm:acl/*1/name") + ":" + map.get("ecm:acl/*1/principal") + ":" + map.get("ecm:acl/*1/permission") + ":" + map.get("ecm:acl/*1/grant") + ":" + map.get("ecm:acl/*1/creator"); Calendar cal = (Calendar) map.get("ecm:acl/*1/begin"); ace += ":" + (cal != null ? cal.getTimeInMillis() : null); cal = (Calendar) map.get("ecm:acl/*1/end"); ace += ":" + (cal != null ? cal.getTimeInMillis() : null); set.add(ace); } res.close(); assertEquals( new HashSet<>( Arrays.asList("local:Administrator:Everything:true:null:null:null", "local:bob:Browse:true:null:null:null", "local:steve:Read:true:null:null:null", "local:leela:Write:true:Administrator:" + begin.getTimeInMillis() + ":" + end.getTimeInMillis(), "local:Everyone:Everything:false:null:null:null")), set); }