/** * Assumes that: - Users have already been converted - Working Sets have already been converted - * Working Set IDs have remained the same. */ protected void run() throws Exception { userIO = new UserIO(session); relationshipIO = new RelationshipIO(session); taxonIO = new TaxonIO(session); if (isTestMode()) print("### RUNNING IN TEST MODE ###"); final WorkingSetIO wsIO = new WorkingSetIO(session); for (VFSPathToken token : data.getOldVFS().list(new VFSPath("/users"))) { final User user = userIO.getUserFromUsername(token.toString()); if (user == null) printf("## No user exists for data directory %s ==", token); else { Hibernate.initialize(user.getSubscribedWorkingSets()); final VFSPath workingSetPath = new VFSPath("/users/" + user.getUsername() + "/workingSet.xml"); final NativeDocument document = new JavaNativeDocument(); try { document.parse(data.getOldVFS().getString(workingSetPath)); } catch (Exception e) { continue; } printf("== Finding working sets for %s (%s) ==", user.getUsername(), user.getId()); final NativeNodeList nodes = document.getDocumentElement().getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { NativeNode node = nodes.item(i); if ("public".equals(node.getNodeName())) { NativeNodeList children = node.getChildNodes(); for (int k = 0; k < children.getLength(); k++) { NativeNode child = children.item(k); if ("workingSet".equals(child.getNodeName())) { NativeElement el = (NativeElement) child; String id = el.getAttribute("id"); String creator = el.getAttribute("creator"); if (!user.getUsername().equals(creator)) { boolean success = wsIO.subscribeToWorkingSet(Integer.valueOf(id), user); if (!success) printf("# Failed to subscribe to ws %s", id); else { printf("Subscribed to ws %s", id); /*if (count.incrementAndGet() % 50 == 0) { printf("Converted %s working set subscriptions...", count.get()); commitAndStartTransaction(); }*/ } } } } } else if ("private".equals(node.getNodeName())) { NativeNodeList children = node.getChildNodes(); for (int k = 0; k < children.getLength(); k++) { NativeNode child = children.item(k); if ("workingSet".equals(child.getNodeName())) { WorkingSetData data = new WorkingSetParser().parseSingleWorkingSet((NativeElement) node); if ("".equals(data.getId())) { continue; } WorkingSet privateWS = WorkingSetConverter.convertWorkingSetData( data, session, relationshipIO, userIO, taxonIO, user); if (privateWS != null) { printf("Created private working set %s", privateWS.getName()); session.save(privateWS); } } } } } } commitAndStartTransaction(); } // commitAndStartTransaction(); }