/**
   * Convert the contents of a ProfileManager to XML and write the XML to the given writer.
   *
   * @param profileManager the ProfileManager
   * @param writer the XMLStreamWriter to write to
   */
  public static void marshal(ProfileManager profileManager, XMLStreamWriter writer) {
    try {
      writer.writeStartElement("userprofiles");
      String profileVersion = getProfileVersion(profileManager.getProfileObjectStoreWriter());
      writer.writeAttribute(MetadataManager.PROFILE_FORMAT_VERSION, profileVersion);
      List<?> usernames = profileManager.getProfileUserNames();

      for (Object userName : usernames) {
        Profile profile = profileManager.getProfile((String) userName);
        LOG.info("Writing profile: " + profile.getUsername());
        long startTime = System.currentTimeMillis();

        ProfileBinding.marshal(
            profile,
            profileManager.getProductionObjectStore(),
            writer,
            profileManager.getVersion(),
            getClassKeys(profileManager.getProductionObjectStore()));

        long totalTime = System.currentTimeMillis() - startTime;
        LOG.info(
            "Finished writing profile: " + profile.getUsername() + " took " + totalTime + "ms.");
      }

      TrackManagerBinding.marshal(profileManager.getProfileObjectStoreWriter(), writer);
      writer.writeEndElement();
    } catch (XMLStreamException e) {
      throw new RuntimeException(e);
    }
  }
示例#2
0
 /** {@inheritDoc} */
 @Override
 public void startElement(String uri, String localName, String qName, Attributes attrs)
     throws SAXException {
   if ("userprofile".equals(qName)) {
     if (attrs.getValue("username") != null) {
       username = attrs.getValue("username");
     }
     if (attrs.getValue("password") != null) {
       password = attrs.getValue("password");
     }
     if (attrs.getValue("apikey") != null) {
       apiKey = attrs.getValue("apikey");
     }
     if (attrs.getValue("localAccount") != null) {
       isLocal = Boolean.parseBoolean(attrs.getValue("localAccount"));
     }
     if (attrs.getValue("superUser") != null) {
       isSuperUser = Boolean.parseBoolean(attrs.getValue("superUser"));
     }
   }
   if ("bags".equals(qName)) {
     savedBags = new LinkedHashMap();
     invalidBags = new LinkedHashMap();
     bagsValues = new LinkedHashMap();
     subHandler =
         new InterMineBagHandler(
             profileManager.getProfileObjectStoreWriter(),
             osw,
             savedBags,
             invalidBags,
             bagsValues);
   }
   if ("shared-bags".equals(qName)) {
     sharedBags = new ArrayList<Map<String, String>>();
     subHandler = new SharedBagHandler(sharedBags);
   }
   if ("template-queries".equals(qName)) {
     savedTemplates = new LinkedHashMap();
     subHandler = new TemplateQueryHandler(savedTemplates, version);
   }
   if ("queries".equals(qName)) {
     savedQueries = new LinkedHashMap();
     subHandler = new SavedQueryHandler(savedQueries, savedBags, version);
   }
   if ("tags".equals(qName)) {
     subHandler = new TagHandler(username, tags);
   }
   if ("preferences".equals(qName)) {
     subHandler = new PreferencesHandler(preferences);
   }
   if ("invitations".equals(qName)) {
     subHandler = invitationHandler;
   }
   if (subHandler != null) {
     subHandler.startElement(uri, localName, qName, attrs);
   }
 }
 /** {@inheritDoc} */
 @Override
 public void startElement(String uri, String localName, String qName, Attributes attrs)
     throws SAXException {
   if ("userprofiles".equals(qName)) {
     String value = attrs.getValue(MetadataManager.PROFILE_FORMAT_VERSION);
     if (value == null) {
       version = 0;
     } else {
       version = Integer.parseInt(value);
     }
     ObjectStoreWriter userprofileOsw = profileManager.getProfileObjectStoreWriter();
     Connection con = null;
     try {
       con = ((ObjectStoreInterMineImpl) userprofileOsw).getConnection();
       if (!DatabaseUtil.tableExists(con, "bagvalues")) {
         DatabaseUtil.createBagValuesTables(con);
       }
     } catch (SQLException sqle) {
       LOG.error("Problem retrieving connection", sqle);
     } finally {
       ((ObjectStoreInterMineImpl) userprofileOsw).releaseConnection(con);
     }
     sharedBagsByUsers = new HashedMap();
   }
   if ("userprofile".equals(qName)) {
     startTime = System.currentTimeMillis();
     profileHandler = new ProfileHandler(profileManager, osw, version, sharedBagsByUsers);
   }
   if (profileHandler != null) {
     profileHandler.startElement(uri, localName, qName, attrs);
   }
   if ("tracks".equals(qName)) {
     trackHandler = new TrackManagerHandler(profileManager.getProfileObjectStoreWriter());
   }
   if (trackHandler != null) {
     trackHandler.startElement(uri, localName, qName, attrs);
   }
 }