public void testAcceptRejectGet() { TestHttpApiClient client = newHttpApiClient(UA_EMPTY, ServerTeam.jcsTicket(), TestApp.APP2_ID, TestApp.APP2_SECRET); client.get( PUB_API + "/suggest/recommend", new Object[][] { {"touser", ServerTeam.CG_ID}, {"suggestedusers", String.valueOf(ServerTeam.WP_ID)} }); client = newHttpApiClient(UA_EMPTY, ServerTeam.grxTicket(), TestApp.APP1_ID, TestApp.APP1_SECRET); client.get( PUB_API + "/psuggest/create", new Object[][] { {"to", ServerTeam.CG_ID}, { "suggested", StringHelper.join( new long[] {ServerTeam.WP_ID, ServerTeam.GRX_ID, ServerTeam.JCS_ID}, ",") } }); client = newHttpApiClient(UA_EMPTY, ServerTeam.cgTicket(), TestApp.APP2_ID, TestApp.APP2_SECRET); client.get( PUB_API + "/psuggest/accept", new Object[][] { {"suggested", ServerTeam.GRX_ID}, { "circles", StringHelper.join(new int[] {Circle.CIRCLE_DEFAULT, Circle.CIRCLE_FAMILY}, ",") } }); client.get(PUB_API + "/psuggest/reject", new Object[][] {{"suggested", ServerTeam.WP_ID}}); AbstractHttpClient.Response resp = client.get(PUB_API + "/psuggest/get", new Object[][] {{"status", Status.ACCEPTED}}); ArrayNode arrNode = (ArrayNode) resp.getJsonNode(); assertEquals(arrNode.size(), 1); assertTrue( JsonCompare.compare( arrNode.get(0).get("suggested"), JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.GRX_ID), false))) .isEquals()); resp = client.get(PUB_API + "/psuggest/get", new Object[][] {{"status", Status.REJECTED}}); arrNode = (ArrayNode) resp.getJsonNode(); assertEquals(arrNode.size(), 1); assertTrue( JsonCompare.compare( arrNode.get(0).get("suggested"), JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.WP_ID), false))) .isEquals()); }
public String createChallangeNAClaims(String req, String claimDefs, int size) throws Exception { ObjectMapper mapper = new ObjectMapper(); ArrayNode claimDefNodes = (ArrayNode) mapper.readTree(claimDefs); req = req.replaceAll("\"", ""); byte[] reqElemBytes = Base64.decode(req); Element reqElem = null; ArrayList<IdentityClaimDefinition> icds = new ArrayList<IdentityClaimDefinition>(); for (int i = 0; i < size; i++) { String onVal = claimDefNodes.get(i).getTextValue(); ObjectNode claimDefOn = (ObjectNode) mapper.readTree(onVal); IdentityClaimDefinition idClaimDef = new IdentityClaimDefinition(claimDefOn); icds.add(idClaimDef); if (reqElem == null) { Pairing pairing = idClaimDef.getParams().getPairing(); reqElem = pairing.getG1().newElement(); reqElem.setFromBytes(reqElemBytes); // System.out.println(reqElem); } } Pairing pairing = icds.get(0).getParams().getPairing(); Field gt = pairing.getGT(); Element sessionKey = gt.newRandomElement().getImmutable(); Element sessionKeyOrig = sessionKey.getImmutable(); // System.out.println("Key: " + sessionKey); JsonNode rootNode = mapper.createObjectNode(); ObjectNode on = (ObjectNode) rootNode; Encrypt encrypt = new Encrypt(); for (int i = 0; i < size; i++) { IdentityClaimDefinition claimDef = icds.get(i); Element share = null; if (i < (size - 1)) { share = gt.newRandomElement().getImmutable(); sessionKey = sessionKey.sub(share).getImmutable(); } else { // Last one should be the remaining part of session key share = sessionKey; } encrypt.init(claimDef.getParams()); // System.out.println("Part : " + i + " : " + share); AECipherTextBlock ct = encrypt.doEncrypt(share, reqElem); on.put(claimDef.getName(), ct.serializeJSON()); } // System.out.println(sessionKeyOrig); String sk = new String(Base64.encode(sessionKeyOrig.toBytes())); sk = sk.replaceAll(" ", ""); on.put("SessionKey", sk); return on.toString(); }
private static Object getValue(Object value, final boolean includeType) { Object returnValue = value; // if the includeType is set to true then show the data types of the properties if (includeType) { // type will be one of: map, list, string, long, int, double, float. // in the event of a complex object it will call a toString and store as a // string String type = determineType(value); ObjectNode valueAndType = jsonNodeFactory.objectNode(); valueAndType.put(GraphSONTokens.TYPE, type); if (type.equals(GraphSONTokens.TYPE_LIST)) { // values of lists must be accumulated as ObjectNode objects under the value key. // will return as a ArrayNode. called recursively to traverse the entire // object graph of each item in the array. ArrayNode list = (ArrayNode) value; // there is a set of values that must be accumulated as an array under a key ArrayNode valueArray = valueAndType.putArray(GraphSONTokens.VALUE); for (int ix = 0; ix < list.size(); ix++) { // the value of each item in the array is a node object from an ArrayNode...must // get the value of it. addObject(valueArray, getValue(getTypedValueFromJsonNode(list.get(ix)), includeType)); } } else if (type.equals(GraphSONTokens.TYPE_MAP)) { // maps are converted to a ObjectNode. called recursively to traverse // the entire object graph within the map. ObjectNode convertedMap = jsonNodeFactory.objectNode(); ObjectNode jsonObject = (ObjectNode) value; Iterator keyIterator = jsonObject.getFieldNames(); while (keyIterator.hasNext()) { Object key = keyIterator.next(); // no need to getValue() here as this is already a ObjectNode and should have type info convertedMap.put(key.toString(), jsonObject.get(key.toString())); } valueAndType.put(GraphSONTokens.VALUE, convertedMap); } else { // this must be a primitive value or a complex object. if a complex // object it will be handled by a call to toString and stored as a // string value putObject(valueAndType, GraphSONTokens.VALUE, value); } // this goes back as a JSONObject with data type and value returnValue = valueAndType; } return returnValue; }
void serialize(ArrayNode container, Map<String, String> namespaces) { ObjectNode ns = (ObjectNode) container.get(0).get(Constants.EJS_NS_KEYWORD); for (String key : namespaces.keySet()) { String value = namespaces.get(key); ns.put(key, value); } }
/** * Handles the given {@link ArrayNode} and writes the responses to the given {@link OutputStream}. * * @param node the {@link JsonNode} * @param ops the {@link OutputStream} * @throws JsonGenerationException * @throws JsonMappingException * @throws IOException */ private void handleArray(ArrayNode node, OutputStream ops) throws JsonGenerationException, JsonMappingException, IOException { // loop through each array element for (int i = 0; i < node.size(); i++) { handleNode(node.get(i), ops); } }
public static String getSubredditId(String mSubreddit) { String subreddit_id = null; JsonNode subredditInfo = RestJsonClient.connect(Constants.REDDIT_BASE_URL + "/r/" + mSubreddit + "/.json?count=1"); if (subredditInfo != null) { ArrayNode children = (ArrayNode) subredditInfo.path("data").path("children"); subreddit_id = children.get(0).get("data").get("subreddit_id").getTextValue(); } return subreddit_id; }
/** * Extracts a list of {@link Currentcontrol} objects from a JSON array. * * @param node ObjectNode containing the list of objects. * @param key Key pointing to the node where the list is stored. */ static List<Currentcontrol> getGUIModelCurrentcontrolList(JsonNode node, String key) { if (node.has(key)) { final ArrayNode a = (ArrayNode) node.get(key); final List<Currentcontrol> l = new ArrayList<Currentcontrol>(a.size()); for (int i = 0; i < a.size(); i++) { l.add(new Currentcontrol((JsonNode) a.get(i))); } return l; } return new ArrayList<Currentcontrol>(0); }
/** * Extracts a list of {@link Skin} objects from a JSON array. * * @param node ObjectNode containing the list of objects. * @param key Key pointing to the node where the list is stored. */ static List<Skin> getGUIModelSkinList(JsonNode node, String key) { if (node.has(key)) { final ArrayNode a = (ArrayNode) node.get(key); final List<Skin> l = new ArrayList<Skin>(a.size()); for (int i = 0; i < a.size(); i++) { l.add(new Skin((JsonNode) a.get(i))); } return l; } return new ArrayList<Skin>(0); }
/** * Extracts a list of {@link PropertyValue} objects from a JSON array. * * @param node ObjectNode containing the list of objects. * @param key Key pointing to the node where the list is stored. */ static List<PropertyValue> getGUIModelPropertyValueList(JsonNode node, String key) { if (node.has(key)) { final ArrayNode a = (ArrayNode) node.get(key); final List<PropertyValue> l = new ArrayList<PropertyValue>(a.size()); for (int i = 0; i < a.size(); i++) { l.add(new PropertyValue((JsonNode) a.get(i))); } return l; } return new ArrayList<PropertyValue>(0); }
/** * Extracts a list of {@link ItemModel.BaseDetails} objects from a JSON array. * * @param obj ObjectNode containing the list of objects * @param key Key pointing to the node where the list is stored */ static ArrayList<ItemModel.BaseDetails> getItemModelBaseDetailsList( ObjectNode node, String key) { if (node.has(key)) { final ArrayNode a = (ArrayNode) node.get(key); final ArrayList<ItemModel.BaseDetails> l = new ArrayList<ItemModel.BaseDetails>(a.size()); for (int i = 0; i < a.size(); i++) { l.add(new ItemModel.BaseDetails((ObjectNode) a.get(i))); } return l; } return new ArrayList<ItemModel.BaseDetails>(0); }
public void testCreateGet() { TestHttpApiClient client = newHttpApiClient(UA_EMPTY, ServerTeam.jcsTicket(), TestApp.APP2_ID, TestApp.APP2_SECRET); AbstractHttpClient.Response resp = client.get( PUB_API + "/suggest/recommend", new Object[][] { {"touser", ServerTeam.CG_ID}, {"suggestedusers", String.valueOf(ServerTeam.WP_ID)} }); assertTrue(resp.getJsonNode().get("result").getBooleanValue()); resp = client.get(PUB_API + "/suggest/get", new Object[][] {{"user_id", ServerTeam.CG_ID}}); ArrayNode arrNode = (ArrayNode) resp.getJsonNode(); assertEquals(arrNode.size(), 1); assertTrue( JsonCompare.compare( arrNode.get(0).get("suggested"), JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.WP_ID), false))) .isEquals()); client = newHttpApiClient(UA_EMPTY, ServerTeam.grxTicket(), TestApp.APP1_ID, TestApp.APP1_SECRET); resp = client.get( PUB_API + "/psuggest/create", new Object[][] { {"to", ServerTeam.CG_ID}, { "suggested", StringHelper.join( new long[] {ServerTeam.WP_ID, ServerTeam.GRX_ID, ServerTeam.JCS_ID}, ",") } }); assertTrue(resp.getJsonNode().get("result").getBooleanValue()); resp = client.get(PUB_API + "/psuggest/get", new Object[][] {{"user_id", ServerTeam.CG_ID}}); arrNode = (ArrayNode) resp.getJsonNode(); assertEquals(arrNode.size(), 2); for (JsonNode node : arrNode) { if (JsonCompare.compare( node.get("suggested"), JsonHelper.parse(JsonHelper.toJson(PeopleId.fromId(ServerTeam.WP_ID), false))) .isEquals()) { assertEquals( node.get("source").getTextValue(), StringHelper.join(new long[] {ServerTeam.JCS_ID, ServerTeam.GRX_ID}, ",")); } } }
protected JsonNode[] sortNodeByName(ArrayNode array) { JsonNode nodes[] = new JsonNode[array.size()]; for (int i = 0; i < array.size(); ++i) { nodes[i] = array.get(i); } Arrays.sort( nodes, new Comparator<JsonNode>() { @Override public int compare(JsonNode o1, JsonNode o2) { final String s1 = o1.get("name").getValueAsText(); final String s2 = o2.get("name").getValueAsText(); return s1.compareTo(s2); } }); return nodes; }
/** * lists caddisfly resources. Source is the json file caddisfly-tests.json stored in * WEB-INF/resources */ public List<CaddisflyResource> listResources() { List<CaddisflyResource> result = new ArrayList<CaddisflyResource>(); try { InputStream stream = getClass() .getClassLoader() .getResourceAsStream("resources/caddisfly/caddisfly-tests.json"); String jsonTxt = IOUtils.toString(stream); // create a list of caddisflyResource objects JsonNode rootNode = mapper.readValue(jsonTxt, JsonNode.class); ArrayNode testsNode = (ArrayNode) rootNode.get("tests"); for (int i = 0; i < testsNode.size(); i++) { CaddisflyResource cr = JsonToCaddisflyResource(testsNode.get(i)); result.add(cr); } } catch (Exception e) { log.log(Level.SEVERE, "Error parsing Caddisfly resource: " + e.getMessage(), e); } return result; }
@Test public void testClientSideUser1() throws Exception { // --------------------------------------------- // Check active factories // --------------------------------------------- TopLevelFolderItemFactory topLevelFolderItemFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory(); assertEquals( "org.nuxeo.drive.hierarchy.permission.factory.PermissionTopLevelFactory", topLevelFolderItemFactory.getName()); Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories(); assertEquals(5, activeFactories.size()); assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory")); assertTrue(activeFactories.contains("defaultFileSystemItemFactory")); assertTrue(activeFactories.contains("userSyncRootParentFactory")); assertTrue(activeFactories.contains("permissionSyncRootFactory")); assertTrue(activeFactories.contains("sharedSyncRootParentFactory")); // --------------------------------------------- // Check top level folder: "Nuxeo Drive" // --------------------------------------------- Blob topLevelFolderJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetTopLevelFolder.ID).execute(); assertNotNull(topLevelFolderJSON); PermissionTopLevelFolderItem topLevelFolder = mapper.readValue(topLevelFolderJSON.getStream(), PermissionTopLevelFolderItem.class); assertNotNull(topLevelFolder); assertEquals(TOP_LEVEL_ID, topLevelFolder.getId()); assertNull(topLevelFolder.getParentId()); assertEquals("/" + TOP_LEVEL_ID, topLevelFolder.getPath()); assertEquals("Nuxeo Drive", topLevelFolder.getName()); assertTrue(topLevelFolder.isFolder()); assertEquals("system", topLevelFolder.getCreator()); assertEquals("system", topLevelFolder.getLastContributor()); assertFalse(topLevelFolder.getCanRename()); assertFalse(topLevelFolder.getCanDelete()); assertFalse(topLevelFolder.getCanCreateChild()); /** * * * <pre> * =================================================== * User workspace registered as a synchronization root * =================================================== * => Expected client side for user1: * * Nuxeo Drive * |-- My Docs * | |-- user1File2 * | |-- user1Folder1 * | | |-- user1File1 * | | |-- user1Folder2 * | |-- user1Folder3 * | | |-- user1File3 * | |-- user1Folder4 * | * |-- Other Docs * | |-- user2Folder1 * | | |-- user2File1 * | | |-- user2Folder2 * | |-- user2Folder3 * | | |-- user2File3 * * </pre> */ TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); nuxeoDriveManager.registerSynchronizationRoot( session1.getPrincipal(), userWorkspace1, session1); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); // --------------------------------------------- // Check top level folder children // --------------------------------------------- Blob topLevelChildrenJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", topLevelFolder.getId()) .execute(); ArrayNode topLevelChildren = mapper.readValue(topLevelChildrenJSON.getStream(), ArrayNode.class); assertNotNull(topLevelChildren); assertEquals(2, topLevelChildren.size()); // Check "My Docs" UserSyncRootParentFolderItem userSyncRootParent = mapper.readValue(topLevelChildren.get(0), UserSyncRootParentFolderItem.class); assertEquals(userWorkspace1ItemId, userSyncRootParent.getId()); assertEquals(TOP_LEVEL_ID, userSyncRootParent.getParentId()); assertEquals(userWorkspace1ItemPath, userSyncRootParent.getPath()); assertEquals("My Docs", userSyncRootParent.getName()); assertTrue(userSyncRootParent.isFolder()); assertEquals("user1", userSyncRootParent.getCreator()); assertEquals("user1", userSyncRootParent.getLastContributor()); assertFalse(userSyncRootParent.getCanRename()); assertFalse(userSyncRootParent.getCanDelete()); // Can create a child since "My Docs" is the user workspace assertTrue(userSyncRootParent.getCanCreateChild()); // Check "Other Docs" SharedSyncRootParentFolderItem sharedSyncRootParent = mapper.readValue(topLevelChildren.get(1), SharedSyncRootParentFolderItem.class); assertEquals(SHARED_SYNC_ROOT_PARENT_ID, sharedSyncRootParent.getId()); assertEquals(TOP_LEVEL_ID, sharedSyncRootParent.getParentId()); assertEquals( "/" + TOP_LEVEL_ID + "/" + SHARED_SYNC_ROOT_PARENT_ID, sharedSyncRootParent.getPath()); assertEquals("Other Docs", sharedSyncRootParent.getName()); assertTrue(sharedSyncRootParent.isFolder()); assertEquals("system", sharedSyncRootParent.getCreator()); assertEquals("system", sharedSyncRootParent.getLastContributor()); assertFalse(sharedSyncRootParent.getCanRename()); assertFalse(sharedSyncRootParent.getCanDelete()); assertFalse(sharedSyncRootParent.getCanCreateChild()); // -------------------------------------------- // Check user synchronization roots // -------------------------------------------- Blob userSyncRootsJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", userSyncRootParent.getId()) .execute(); ArrayNode userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class); assertNotNull(userSyncRoots); assertEquals(4, userSyncRoots.size()); DocumentBackedFolderItem folderItem; DocumentBackedFileItem childFileItem; DocumentBackedFileItem fileItem; DocumentBackedFolderItem childFolderItem; JsonNode[] rootNodes = sortNodeByName(userSyncRoots); // user1File2 fileItem = mapper.readValue(rootNodes[0], DocumentBackedFileItem.class); checkFileItem( fileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File2, userWorkspace1ItemId, userWorkspace1ItemPath, "user1File2.txt", "user1", "user1"); // user1Folder1 folderItem = mapper.readValue(rootNodes[1], DocumentBackedFolderItem.class); checkFolderItem( folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder1, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder1", "user1", "user1"); Blob folderItemChildrenJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", folderItem.getId()) .execute(); ArrayNode folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class); assertNotNull(folderItemChildren); assertEquals(2, folderItemChildren.size()); { JsonNode[] nodes = sortNodeByName(folderItemChildren); // user1File1 childFileItem = mapper.readValue(nodes[0], DocumentBackedFileItem.class); checkFileItem( childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File1, folderItem.getId(), folderItem.getPath(), "user1File1.txt", "user1", "user1"); // user1Folder2 childFolderItem = mapper.readValue(nodes[1], DocumentBackedFolderItem.class); checkFolderItem( childFolderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder2, folderItem.getId(), folderItem.getPath(), "user1Folder2", "user1", "user1"); } // user1Folder3 folderItem = mapper.readValue(rootNodes[2], DocumentBackedFolderItem.class); checkFolderItem( folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder3, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder3", "user1", "user1"); { folderItemChildrenJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", folderItem.getId()) .execute(); folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class); assertNotNull(folderItemChildren); assertEquals(1, folderItemChildren.size()); // user1File3 childFileItem = mapper.readValue(folderItemChildren.get(0), DocumentBackedFileItem.class); checkFileItem( childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File3, folderItem.getId(), folderItem.getPath(), "user1File3.txt", "user1", "user1"); } // user1Folder4 folderItem = mapper.readValue(rootNodes[3], DocumentBackedFolderItem.class); checkFolderItem( folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder4, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder4", "user1", "user1"); // --------------------------------------------- // Check shared synchronization roots // --------------------------------------------- Blob sharedSyncRootsJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", sharedSyncRootParent.getId()) .execute(); List<DefaultSyncRootFolderItem> sharedSyncRoots = mapper.readValue( sharedSyncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {}); Collections.sort(sharedSyncRoots); assertNotNull(sharedSyncRoots); assertEquals(2, sharedSyncRoots.size()); // user2Folder1 DefaultSyncRootFolderItem sharedSyncRoot = sharedSyncRoots.get(0); checkFolderItem( sharedSyncRoot, SYNC_ROOT_ID_PREFIX, session1.getDocument(user2Folder1.getRef()), sharedSyncRootParent.getId(), sharedSyncRootParent.getPath(), "user2Folder1", "user2", "user1"); Blob sharedSyncRootChildrenJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", sharedSyncRoot.getId()) .execute(); ArrayNode sharedSyncRootChildren = mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class); assertNotNull(sharedSyncRootChildren); assertEquals(2, sharedSyncRootChildren.size()); DocumentBackedFolderItem sharedSyncRootChildFolderItem; DocumentBackedFileItem sharedSyncRootChildFileItem; { JsonNode[] nodes = sortNodeByName(sharedSyncRootChildren); // user2File1 sharedSyncRootChildFileItem = mapper.readValue(nodes[0], DocumentBackedFileItem.class); checkFileItem( sharedSyncRootChildFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2File1.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2File1.txt", "user2", "user2"); // user2Folder2 sharedSyncRootChildFolderItem = mapper.readValue(nodes[1], DocumentBackedFolderItem.class); checkFolderItem( sharedSyncRootChildFolderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2Folder2.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2Folder2", "user2", "user2"); } // user2Folder3 sharedSyncRoot = sharedSyncRoots.get(1); checkFolderItem( sharedSyncRoot, SYNC_ROOT_ID_PREFIX, session1.getDocument(user2Folder3.getRef()), sharedSyncRootParent.getId(), sharedSyncRootParent.getPath(), "user2Folder3", "user2", "user1"); sharedSyncRootChildrenJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", sharedSyncRoot.getId()) .execute(); sharedSyncRootChildren = mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class); assertNotNull(sharedSyncRootChildren); assertEquals(1, sharedSyncRootChildren.size()); // user2File3 sharedSyncRootChildFileItem = mapper.readValue(sharedSyncRootChildren.get(0), DocumentBackedFileItem.class); checkFileItem( sharedSyncRootChildFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2File3.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2File3.txt", "user2", "user2"); /** * * * <pre> * ======================================================= * User workspace NOT registered as a synchronization root * ======================================================= * => Expected client side for user1: * * Nuxeo Drive * |-- My Docs * | * |-- Other Docs (unchanged) * | |-- user2Folder1 * | | |-- user2File1 * | | |-- user2Folder2 * | |-- user2Folder3 * | | |-- user2File3 * * </pre> */ TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); nuxeoDriveManager.unregisterSynchronizationRoot( session1.getPrincipal(), userWorkspace1, session1); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); // --------------------------------------------- // Check "My Docs" // --------------------------------------------- Blob userSyncRootParentJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetFileSystemItem.ID) .set("id", userWorkspace1ItemId) .execute(); assertNotNull(userSyncRootParentJSON); userSyncRootParent = mapper.readValue(userSyncRootParentJSON.getStream(), UserSyncRootParentFolderItem.class); assertEquals(userWorkspace1ItemId, userSyncRootParent.getId()); assertEquals(TOP_LEVEL_ID, userSyncRootParent.getParentId()); assertEquals(userWorkspace1ItemPath, userSyncRootParent.getPath()); assertEquals("My Docs", userSyncRootParent.getName()); assertTrue(userSyncRootParent.isFolder()); assertEquals("user1", userSyncRootParent.getCreator()); assertEquals("user1", userSyncRootParent.getLastContributor()); assertFalse(userSyncRootParent.getCanRename()); assertFalse(userSyncRootParent.getCanDelete()); // Cannot create a child since "My Docs" is only the parent of the // synchronization roots, not the user workspace assertFalse(userSyncRootParent.getCanCreateChild()); // -------------------------------------------- // Check user synchronization roots // -------------------------------------------- userSyncRootsJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", userSyncRootParent.getId()) .execute(); userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class); assertNotNull(userSyncRoots); assertEquals(0, userSyncRoots.size()); /** * * * <pre> * ======================================================= * User workspace NOT registered as a synchronization root * but specific folders yes: user1Folder3, user1Folder4 * ======================================================= * => Expected client side for user1: * * Nuxeo Drive * |-- My Docs * | |-- user1Folder3 * | | |-- user1File3 * | |-- user1Folder4 * | * |-- Other Docs (unchanged) * | |-- user2Folder1 * | | |-- user2File1 * | | |-- user2Folder2 * | |-- user2Folder3 * | | |-- user2File3 * * </pre> */ TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), user1Folder3, session1); nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), user1Folder4, session1); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); // -------------------------------------------- // Check user synchronization roots // -------------------------------------------- userSyncRootsJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", userSyncRootParent.getId()) .execute(); userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class); assertNotNull(userSyncRoots); assertEquals(2, userSyncRoots.size()); // user1Folder3 folderItem = mapper.readValue(userSyncRoots.get(0), DocumentBackedFolderItem.class); checkFolderItem( folderItem, SYNC_ROOT_ID_PREFIX, user1Folder3, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder3", "user1", "user1"); folderItemChildrenJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", folderItem.getId()) .execute(); folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class); assertNotNull(folderItemChildren); assertEquals(1, folderItemChildren.size()); // user1File3 childFileItem = mapper.readValue(folderItemChildren.get(0), DocumentBackedFileItem.class); checkFileItem( childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File3, folderItem.getId(), folderItem.getPath(), "user1File3.txt", "user1", "user1"); // user1Folder4 folderItem = mapper.readValue(userSyncRoots.get(1), DocumentBackedFolderItem.class); checkFolderItem( folderItem, SYNC_ROOT_ID_PREFIX, user1Folder4, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder4", "user1", "user1"); /** * * * <pre> * ======================================================= * Unregister a shared folder: user2Folder1 * ======================================================= * => Expected client side for user1: * * Nuxeo Drive * |-- My Docs (unchanged) * | |-- user1Folder3 * | | |-- user1File3 * | |-- user1Folder4 * | * |-- Other Docs * | |-- user2Folder3 * | | |-- user2File3 * * </pre> */ TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); nuxeoDriveManager.unregisterSynchronizationRoot( session1.getPrincipal(), session1.getDocument(user2Folder1.getRef()), session1); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); // --------------------------------------------- // Check shared synchronization roots // --------------------------------------------- sharedSyncRootsJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", sharedSyncRootParent.getId()) .execute(); sharedSyncRoots = mapper.readValue( sharedSyncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {}); assertNotNull(sharedSyncRoots); assertEquals(1, sharedSyncRoots.size()); // user2Folder3 sharedSyncRoot = sharedSyncRoots.get(0); checkFolderItem( sharedSyncRoot, SYNC_ROOT_ID_PREFIX, session1.getDocument(user2Folder3.getRef()), sharedSyncRootParent.getId(), sharedSyncRootParent.getPath(), "user2Folder3", "user2", "user1"); sharedSyncRootChildrenJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", sharedSyncRoot.getId()) .execute(); sharedSyncRootChildren = mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class); assertNotNull(sharedSyncRootChildren); assertEquals(1, sharedSyncRootChildren.size()); // user2File3 sharedSyncRootChildFileItem = mapper.readValue(sharedSyncRootChildren.get(0), DocumentBackedFileItem.class); checkFileItem( sharedSyncRootChildFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2File3.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2File3.txt", "user2", "user2"); /** * * * <pre> * ======================================================= * Remove permission on a shared folder: user2Folder3 * ======================================================= * => Expected client side for user1: * * Nuxeo Drive * |-- My Docs (unchanged) * | |-- user1Folder3 * | | |-- user1File3 * | |-- user1Folder4 * | * |-- Other Docs * * </pre> */ resetPermissions(user2Folder3.getRef(), "user1"); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); // --------------------------------------------- // Check shared synchronization roots // --------------------------------------------- sharedSyncRootsJSON = (Blob) clientSession1 .newRequest(NuxeoDriveGetChildren.ID) .set("id", sharedSyncRootParent.getId()) .execute(); sharedSyncRoots = mapper.readValue( sharedSyncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {}); assertNotNull(sharedSyncRoots); assertEquals(0, sharedSyncRoots.size()); }
/** * @param request * @param claimDefs Array of claim defs * @return * @throws Exception */ public String createChallangeNClaimsThreads(String requests, String claimDefs) throws Exception { ObjectMapper mapper = new ObjectMapper(); // System.out.println(requests); String[] split = requests.split(","); ArrayNode claimDefNodes = (ArrayNode) mapper.readTree(claimDefs); ArrayList<IdentityClaimDefinition> icds = new ArrayList<IdentityClaimDefinition>(); ArrayList<Element> reqs = new ArrayList<Element>(); for (int i = 0; i < split.length; i++) { String onVal = claimDefNodes.get(i).getTextValue(); ObjectNode claimDefOn = (ObjectNode) mapper.readTree(onVal); IdentityClaimDefinition idClaimDef = new IdentityClaimDefinition(claimDefOn); icds.add(idClaimDef); Pairing pairing = idClaimDef.getParams().getPairing(); // System.out.println(idClaimDef.serializeJSON()); String tmpReq = split[i].replaceAll("\"", ""); byte[] reqElemBytes = Base64.decode(tmpReq); // System.out.println(reqElemBytes.length); Element reqElem = pairing.getG1().newElement(); reqElem.setFromBytes(reqElemBytes); // System.out.println(reqElem.getImmutable()); reqs.add(reqElem); } Pairing pairing = icds.get(0).getParams().getPairing(); Field gt = pairing.getGT(); Element sessionKey = gt.newRandomElement().getImmutable(); Element sessionKeyOrig = sessionKey.getImmutable(); // System.out.println("Key: " + sessionKey); JsonNode rootNode = mapper.createObjectNode(); ObjectNode on = (ObjectNode) rootNode; ArrayList<EncrypterThread> ets = new ArrayList<ServiceProvider.EncrypterThread>(); for (int i = 0; i < split.length; i++) { IdentityClaimDefinition claimDef = icds.get(i); Element share = null; if (i < (split.length - 1)) { share = gt.newRandomElement().getImmutable(); sessionKey = sessionKey.sub(share).getImmutable(); } else { // Last one should be the remaining part of session key share = sessionKey; } EncrypterThread t = new EncrypterThread(claimDef.getName(), claimDef.getParams(), share, reqs.get(i), on); t.start(); ets.add(t); } for (EncrypterThread t : ets) { t.join(); } String sk = new String(Base64.encode(sessionKeyOrig.toBytes())); sk = sk.replaceAll(" ", ""); on.put("SessionKey", sk); return on.toString(); }
public void fromJson(ObjectNode node, IndexDefinitionImpl index) { IndexGeneralState state = IndexGeneralState.valueOf(JsonUtil.getString(node, "generalState")); IndexUpdateState updateState = IndexUpdateState.valueOf(JsonUtil.getString(node, "updateState")); IndexBatchBuildState buildState = IndexBatchBuildState.valueOf(JsonUtil.getString(node, "batchBuildState")); String queueSubscriptionId = JsonUtil.getString(node, "queueSubscriptionId", null); byte[] configuration; try { String configurationAsString = JsonUtil.getString(node, "configuration"); configuration = Base64.decode(configurationAsString); } catch (IOException e) { throw new RuntimeException(e); } byte[] shardingConfiguration = null; if (node.get("shardingConfiguration") != null) { String shardingConfAsString = JsonUtil.getString(node, "shardingConfiguration"); try { shardingConfiguration = Base64.decode(shardingConfAsString); } catch (IOException e) { throw new RuntimeException(e); } } Map<String, String> solrShards = new HashMap<String, String>(); ArrayNode shardsArray = JsonUtil.getArray(node, "solrShards"); for (int i = 0; i < shardsArray.size(); i++) { ObjectNode shardNode = (ObjectNode) shardsArray.get(i); String shardName = JsonUtil.getString(shardNode, "name"); String address = JsonUtil.getString(shardNode, "address"); solrShards.put(shardName, address); } ActiveBatchBuildInfo activeBatchBuild = null; if (node.get("activeBatchBuild") != null) { ObjectNode buildNode = JsonUtil.getObject(node, "activeBatchBuild"); activeBatchBuild = new ActiveBatchBuildInfo(); activeBatchBuild.setJobId(JsonUtil.getString(buildNode, "jobId")); activeBatchBuild.setSubmitTime(JsonUtil.getLong(buildNode, "submitTime")); activeBatchBuild.setTrackingUrl(JsonUtil.getString(buildNode, "trackingUrl", null)); activeBatchBuild.setBatchIndexConfiguration( serializeJsonNode(JsonUtil.getObject(buildNode, "batchIndexConfiguration"))); } BatchBuildInfo lastBatchBuild = null; if (node.get("lastBatchBuild") != null) { ObjectNode buildNode = JsonUtil.getObject(node, "lastBatchBuild"); lastBatchBuild = new BatchBuildInfo(); lastBatchBuild.setJobId(JsonUtil.getString(buildNode, "jobId")); lastBatchBuild.setSubmitTime(JsonUtil.getLong(buildNode, "submitTime")); lastBatchBuild.setSuccess(JsonUtil.getBoolean(buildNode, "success")); lastBatchBuild.setJobState(JsonUtil.getString(buildNode, "jobState")); lastBatchBuild.setTrackingUrl(JsonUtil.getString(buildNode, "trackingUrl", null)); ObjectNode countersNode = JsonUtil.getObject(buildNode, "counters"); Iterator<String> it = countersNode.getFieldNames(); while (it.hasNext()) { String key = it.next(); long value = JsonUtil.getLong(countersNode, key); lastBatchBuild.addCounter(key, value); } lastBatchBuild.setBatchIndexConfiguration( serializeJsonNode(JsonUtil.getObject(buildNode, "batchIndexConfiguration"))); } byte[] batchIndexConfiguration = null; if (node.get("batchIndexConfiguration") != null) { batchIndexConfiguration = serializeJsonNode(JsonUtil.getObject(node, "batchIndexConfiguration")); } byte[] defaultBatchIndexConfiguration = null; if (node.get("defaultBatchIndexConfiguration") != null) { defaultBatchIndexConfiguration = serializeJsonNode(JsonUtil.getObject(node, "defaultBatchIndexConfiguration")); } index.setGeneralState(state); index.setUpdateState(updateState); index.setBatchBuildState(buildState); index.setQueueSubscriptionId(queueSubscriptionId); index.setConfiguration(configuration); index.setSolrShards(solrShards); index.setShardingConfiguration(shardingConfiguration); index.setActiveBatchBuildInfo(activeBatchBuild); index.setLastBatchBuildInfo(lastBatchBuild); index.setBatchIndexConfiguration(batchIndexConfiguration); index.setDefaultBatchIndexConfiguration(defaultBatchIndexConfiguration); }