Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Move ApplicationInfo to Core package, use "application_info" type con…
Browse files Browse the repository at this point in the history
…sistently across entire codebase.
  • Loading branch information
Dave Johnson committed Mar 3, 2015
1 parent 485f578 commit 6791df6
Show file tree
Hide file tree
Showing 48 changed files with 119 additions and 219 deletions.
Expand Up @@ -37,6 +37,7 @@
import org.apache.usergrid.persistence.EntityRef;
import org.apache.usergrid.persistence.Results;
import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
import org.apache.usergrid.persistence.cassandra.CassandraService;
import org.apache.usergrid.persistence.cassandra.CounterUtils;
Expand All @@ -49,6 +50,7 @@
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.core.util.Health;
import org.apache.usergrid.persistence.entities.Application;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
import org.apache.usergrid.persistence.exceptions.DuplicateUniquePropertyExistsException;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
Expand Down Expand Up @@ -250,20 +252,19 @@ public UUID initializeApplication( String organizationName, UUID applicationId,
}

em.refreshIndex();
orgUuid = orgInfo.getUuid();
}

// create appinfo entry in the system app
final UUID appId = applicationId;
final UUID orgId = orgUuid;
Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
put( PROPERTY_NAME, appName );
put( "applicationUuid", appId );
put( PROPERTY_UUID, appId );
put( "organizationUuid", orgId );
}};

try {
em.create(CpNamingUtils.APPLICATION_INFO, appInfoMap);
em.create( appId, CpNamingUtils.APPLICATION_INFO, appInfoMap );
} catch (DuplicateUniquePropertyExistsException e) {
throw new ApplicationAlreadyExistsException(appName);
}
Expand Down Expand Up @@ -385,36 +386,17 @@ public UUID lookupOrganization( String name ) throws Exception {
public UUID lookupApplication( String name ) throws Exception {
init();

// TODO: why does this not work for restored apps

// EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID );
// final EntityRef alias = em.getAlias( CpNamingUtils.APPINFOS, name );
// if ( alias == null ) {
// return null;
// }
// final Entity entity = em.get( alias );
// if ( entity == null ) {
// return null;
// }
// final UUID property = ( UUID ) entity.getProperty( "applicationUuid" );
// return property;

Query q = Query.fromQL( PROPERTY_NAME + " = '" + name + "'");

EntityManager em = getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);

Results results = em.searchCollection( em.getApplicationRef(), CpNamingUtils.APPLICATION_INFOS, q);

if ( results.isEmpty() ) {
EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
final EntityRef alias = em.getAlias( CpNamingUtils.APPLICATION_INFO, name );
if ( alias == null ) {
return null;
}

Entity entity = results.iterator().next();
Object uuidObject = entity.getProperty("applicationUuid");
if ( uuidObject instanceof UUID ) {
return (UUID)uuidObject;
final Entity entity = em.get( alias );
if ( entity == null ) {
return null;
}
return UUIDUtils.tryExtractUUID( entity.getProperty("applicationUuid").toString() );
final UUID property = ( UUID ) entity.getProperty( "uuid" );
return property;
}


Expand Down
Expand Up @@ -58,13 +58,13 @@ public class CpNamingUtils {
/**
* The app infos entity object type. This holds the app name, appId, and org name
*/
public static final String APPLICATION_INFO = "appinfo";
public static final String APPLICATION_INFO = "application_info";

public static final String APPLICATION_INFOS = "appinfos";
public static final String APPLICATION_INFOS = "application_infos";

public static final String DELETED_APPINFO = "deleted_appinfo";
public static final String DELETED_APPINFO = "deleted_application_info";

public static final String DELETED_APPINFOS = "deleted_appinfos";
public static final String DELETED_APPINFOS = "deleted_application_infos";

/**
* The name of the map that holds our entity id->type mapping
Expand Down
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.usergrid.management;
package org.apache.usergrid.persistence.entities;


import java.util.ArrayList;
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.UUID;

import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -221,7 +222,8 @@ public void testCommunityCounters() throws Exception {

Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "name", orgName + "/" + appName );
Entity applicationEntity = em.create( applicationId, "application_info", properties );
Entity applicationEntity = em.create(
applicationId, CpNamingUtils.APPLICATION_INFO, properties );

//Creating connections like below doesn't work.
// em.createConnection( new SimpleEntityRef( "group", organizationEntity.getUuid() ), "owns",
Expand Down
Expand Up @@ -26,6 +26,7 @@
import java.util.Set;
import java.util.UUID;

import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
Expand Down Expand Up @@ -392,10 +393,10 @@ public void testEntityCounters() throws Exception {

Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "name", "testEntityCounters" );
Entity applicationEntity = em.create( applicationId, "application_info", properties );
Entity applicationEntity = em.create( applicationId, CpNamingUtils.APPLICATION_INFO, properties );

em.createConnection( new SimpleEntityRef( "group", organizationEntity.getUuid() ), "owns",
new SimpleEntityRef( "application_info", applicationId ) );
new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ) );

em = setup.getEmf().getEntityManager( applicationId );
properties = new LinkedHashMap<String, Object>();
Expand Down
Expand Up @@ -19,7 +19,7 @@

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.protocol.OpQuery;
import org.apache.usergrid.mongo.protocol.OpReply;
Expand Down
Expand Up @@ -21,7 +21,7 @@
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.protocol.OpQuery;
import org.apache.usergrid.mongo.protocol.OpReply;
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.query.MongoQueryParser;
import org.apache.usergrid.mongo.utils.BSONUtils;
Expand Down Expand Up @@ -122,7 +122,7 @@ public ChannelBuffer encode( ChannelBuffer buffer ) {

/*
* (non-Javadoc)
*
*
* @see org.apache.usergrid.mongo.protocol.OpCrud#doOp(org.apache.usergrid.mongo.
* MongoChannelHandler, org.jboss.netty.channel.ChannelHandlerContext,
* org.jboss.netty.channel.MessageEvent)
Expand Down Expand Up @@ -185,7 +185,7 @@ public OpReply doOp( MongoChannelHandler handler, ChannelHandlerContext ctx, Mes

/*
* (non-Javadoc)
*
*
* @see java.lang.Object#toString()
*/
@Override
Expand Down
Expand Up @@ -32,7 +32,7 @@
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.utils.BSONUtils;
import org.apache.usergrid.persistence.EntityManager;
Expand Down
Expand Up @@ -34,7 +34,7 @@
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.management.UserInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.commands.MongoCommand;
Expand Down Expand Up @@ -211,7 +211,7 @@ public ChannelBuffer encode( ChannelBuffer buffer ) {

/*
* (non-Javadoc)
*
*
* @see org.apache.usergrid.mongo.protocol.OpCrud#doOp()
*/
@Override
Expand Down Expand Up @@ -281,8 +281,8 @@ private OpReply handleAuthenticate( MongoChannelHandler handler, String database
return handleAuthFails( this );
}

PrincipalCredentialsToken token =
PrincipalCredentialsToken.getFromAdminUserInfoAndPassword(
PrincipalCredentialsToken token =
PrincipalCredentialsToken.getFromAdminUserInfoAndPassword(
user, key, handler.getEmf().getManagementAppId() );
Subject subject = SubjectUtils.getSubject();

Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.query.MongoQueryParser;
import org.apache.usergrid.mongo.utils.BSONUtils;
Expand Down Expand Up @@ -140,7 +140,7 @@ public ChannelBuffer encode( ChannelBuffer buffer ) {

/*
* (non-Javadoc)
*
*
* @see org.apache.usergrid.mongo.protocol.OpCrud#doOp(org.apache.usergrid.mongo.
* MongoChannelHandler, org.jboss.netty.channel.ChannelHandlerContext,
* org.jboss.netty.channel.MessageEvent)
Expand Down Expand Up @@ -195,7 +195,7 @@ public OpReply doOp( MongoChannelHandler handler, ChannelHandlerContext ctx, Mes

/*
* (non-Javadoc)
*
*
* @see java.lang.Object#toString()
*/
@Override
Expand Down
Expand Up @@ -30,19 +30,14 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
import org.apache.usergrid.rest.ApiResponse;
import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
import org.apache.usergrid.services.ServiceAction;
import org.apache.usergrid.services.ServiceResults;
import org.apache.usergrid.services.assets.data.AssetUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.apache.usergrid.exception.NotImplementedException;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.management.exceptions.DisabledAdminUserException;
import org.apache.usergrid.management.exceptions.DisabledAppUserException;
import org.apache.usergrid.management.exceptions.UnactivatedAdminUserException;
Expand Down Expand Up @@ -546,8 +541,8 @@ public JSONWithPadding executeDelete( @Context UriInfo ui,

ApiResponse response = createApiResponse();
response.setAction( "delete" );
response.setApplication( services.getApplication() );
response.setParams( ui.getQueryParameters() );
response.setApplication(services.getApplication());
response.setParams(ui.getQueryParameters());

return new JSONWithPadding( response, callback );
}
Expand Down
Expand Up @@ -17,34 +17,20 @@
package org.apache.usergrid.rest.management.organizations.applications;


import com.amazonaws.AmazonClientException;
import com.amazonaws.SDKGlobalConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.google.common.base.Preconditions;
import com.sun.jersey.api.json.JSONWithPadding;
import org.apache.amber.oauth2.common.exception.OAuthSystemException;
import org.apache.amber.oauth2.common.message.OAuthResponse;
import org.apache.commons.lang.StringUtils;

import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.export.ExportService;
import org.apache.usergrid.management.importer.ImportService;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityRef;
import org.apache.usergrid.persistence.SimpleEntityRef;
import org.apache.usergrid.persistence.entities.Import;
import org.apache.usergrid.persistence.index.query.Query;
import org.apache.usergrid.persistence.queue.impl.SQSQueueManagerImpl;
import org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentials;
import org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentialsProvider;
import org.apache.usergrid.rest.AbstractContextResource;
import org.apache.usergrid.rest.ApiResponse;
import org.apache.usergrid.rest.applications.ServiceResource;
import org.apache.usergrid.rest.management.organizations.applications.imports.ImportsResource;
import org.apache.usergrid.rest.security.annotations.RequireAdminUserAccess;
import org.apache.usergrid.rest.security.annotations.RequireApplicationAccess;
import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
import org.apache.usergrid.rest.utils.JSONPUtils;
import org.apache.usergrid.security.oauth.ClientCredentialsInfo;
Expand All @@ -61,7 +47,6 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

Expand Down
Expand Up @@ -31,7 +31,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
import org.apache.usergrid.rest.AbstractContextResource;
Expand Down
Expand Up @@ -37,7 +37,7 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.management.importer.ImportService;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.Results;
Expand Down
Expand Up @@ -21,14 +21,9 @@


import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
Expand All @@ -42,19 +37,15 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.management.importer.ImportService;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.Results;
import org.apache.usergrid.persistence.entities.FileImport;
import org.apache.usergrid.persistence.entities.Import;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
import org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentials;
import org.apache.usergrid.rest.AbstractContextResource;
import org.apache.usergrid.rest.ApiResponse;
import org.apache.usergrid.rest.RootResource;
import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;

import com.sun.jersey.api.json.JSONWithPadding;

Expand Down

0 comments on commit 6791df6

Please sign in to comment.