Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright 2012 Apigee Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.usergrid.tools;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.apache.commons.cli.CommandLine;
import org.codehaus.jackson.JsonEncoding;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usergrid.management.OrganizationInfo;
import org.usergrid.management.UserInfo;
import org.usergrid.persistence.ConnectionRef;
import org.usergrid.persistence.Entity;
import org.usergrid.persistence.EntityManager;
import org.usergrid.persistence.Query;
import org.usergrid.persistence.Results;
import org.usergrid.persistence.Results.Level;
import org.usergrid.persistence.cassandra.CassandraService;
import org.usergrid.tools.bean.ExportOrg;
import org.usergrid.utils.JsonUtils;
import com.google.common.collect.BiMap;
public class Export extends ExportingToolBase {
static final Logger logger = LoggerFactory.getLogger(Export.class);
JsonFactory jsonFactory = new JsonFactory();
@Override
public void runTool(CommandLine line) throws Exception {
startSpring();
setVerbose(line);
// ExportDataCreator dataCreator = new ExportDataCreator(emf,
// managementService);
// dataCreator.createTestData();
applyOrgId(line);
prepareBaseOutputFileName(line);
outputDir = createOutputParentDir();
logger.info("Export directory: " + outputDir.getAbsolutePath());
// Export organizations separately.
exportOrganizations();
// Loop through the organizations
Map organizations = getOrgs();
for (Entry organization : organizations.entrySet()) {
if (organization.equals(properties.getProperty("usergrid.test-account.organization"))) {
// Skip test data from being exported.
continue;
}
exportApplicationsForOrg(organization);
}
}
private Map getOrgs() throws Exception{
// Loop through the organizations
Map organizationNames = null;
if(orgId == null){
organizationNames = managementService.getOrganizations();
}
else{
OrganizationInfo info = managementService.getOrganizationByUuid(orgId);
if(info == null){
logger.error("Organization info is null!");
System.exit(1);
}
organizationNames = new HashMap();
organizationNames.put(orgId, info.getName());
}
return organizationNames;
}
private void exportApplicationsForOrg(Entry organization) throws Exception {
logger.info("" + organization);
// Loop through the applications per organization
BiMap applications = managementService.getApplicationsForOrganization(organization.getKey());
for (Entry application : applications.entrySet()) {
logger.info(application.getValue() + " : " + application.getKey());
// Get the JSon serializer.
JsonGenerator jg = getJsonGenerator(createOutputFile("application", application.getValue()));
// load the dictionary
EntityManager rootEm = emf.getEntityManager(CassandraService.MANAGEMENT_APPLICATION_ID);
Entity appEntity = rootEm.get(application.getKey());
Map dictionaries = new HashMap();
for (String dictionary : rootEm.getDictionaries(appEntity)) {
Map