You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/02/11 18:23:54 UTC
[1/3] incubator-usergrid git commit: Updated resource framework.
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o-import ef2bdc027 -> db8184c84
Updated resource framework.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/bb6ac19d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/bb6ac19d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/bb6ac19d
Branch: refs/heads/two-dot-o-import
Commit: bb6ac19dca76aeec34a155817c8a2a29d45a9e52
Parents: 151d8cc
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Feb 11 09:52:15 2015 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Feb 11 09:52:15 2015 -0700
----------------------------------------------------------------------
.../org/apache/usergrid/rest/ApiResponse.java | 16 ++
.../imports/FileErrorsResource.java | 143 +++++++++++++++
.../imports/FileIncludesResource.java | 175 +++++++++++++++++++
.../applications/imports/ImportResource.java | 98 -----------
.../applications/imports/ImportsResource.java | 82 +++++----
.../management/importer/ImportService.java | 45 +++++
.../management/importer/ImportServiceImpl.java | 61 +++++--
7 files changed, 474 insertions(+), 146 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bb6ac19d/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java b/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
index 3df3df4..d7dd5f8 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
@@ -35,6 +35,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.usergrid.persistence.AggregateCounterSet;
import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.Results;
import org.apache.usergrid.persistence.entities.Application;
import org.apache.usergrid.security.oauth.ClientCredentialsInfo;
import org.apache.usergrid.services.ServiceRequest;
@@ -378,6 +379,21 @@ public class ApiResponse {
}
+ /**
+ * Set the response from the EM results
+ * @param results
+ * @return
+ */
+ public ApiResponse withResults(Results results){
+ entities = results.getEntities();
+ next = results.getNextResult();
+ cursor = results.getCursor();
+ counters = results.getCounters();
+
+ return this;
+ }
+
+
public ApiResponse withResults( ServiceResults results ) {
setResults( results );
return this;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bb6ac19d/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
new file mode 100644
index 0000000..552b3b5
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.usergrid.rest.management.organizations.applications.imports;
+
+
+import java.util.Collections;
+import java.util.UUID;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriInfo;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import org.apache.usergrid.management.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.FailedImportEntity;
+import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
+import org.apache.usergrid.rest.AbstractContextResource;
+import org.apache.usergrid.rest.ApiResponse;
+import org.apache.usergrid.rest.RootResource;
+
+import com.sun.jersey.api.json.JSONWithPadding;
+
+
+@Component("org.apache.usergrid.rest.management.organizations.applications.imports.FileErrorsResource")
+@Scope("prototype")
+@Produces(MediaType.APPLICATION_JSON)
+public class FileErrorsResource extends AbstractContextResource {
+
+
+ @Autowired
+ protected ImportService importService;
+
+ private ApplicationInfo application;
+ private UUID importId;
+ private UUID importFileId;
+
+ /**
+ * Override our service manager factory so that we get entities from the root management app
+ */
+ public FileErrorsResource() {
+ //override the services management app
+
+ }
+
+
+ public FileErrorsResource init( final ApplicationInfo application, final UUID importId, final UUID importFileId){
+ this.application = application;
+ this.importId = importId;
+ this.importFileId = importFileId;
+ return this;
+ }
+
+
+
+ @GET
+ public JSONWithPadding getFileIncludes( @Context UriInfo ui, @QueryParam( "cursor" ) String cursor )
+ throws Exception {
+
+
+ final Results importResults = importService.getFailedImportEntities( application.getId(), importId,
+ importFileId, cursor );
+
+ if(importResults == null){
+ throw new EntityNotFoundException( "could not load import results" );
+ }
+
+ ApiResponse response = createApiResponse();
+
+
+ response.setAction( "get" );
+ response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
+ response.setParams( ui.getQueryParameters() );
+
+
+ response.withResults( importResults );
+
+ return new JSONWithPadding( response );
+
+ }
+
+ @GET
+ @Path( RootResource.ENTITY_ID_PATH )
+ public JSONWithPadding getFileIncludeById( @Context UriInfo ui, @PathParam( "entityId" ) PathSegment entityId )
+ throws Exception {
+
+ final UUID failedEntity = UUID.fromString( entityId.getPath() );
+ final FailedImportEntity
+ importEntity = importService.getFailedImportEntity( application.getId(), importId, importFileId,
+ failedEntity );
+
+ if(importEntity == null){
+ throw new EntityNotFoundException( "could not find import with uuid " + importId );
+ }
+
+ ApiResponse response = createApiResponse();
+
+
+ response.setAction( "get" );
+ response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
+ response.setParams( ui.getQueryParameters() );
+
+
+ response.setEntities( Collections.<Entity>singletonList( importEntity ) );
+
+ return new JSONWithPadding( response );
+
+ }
+
+
+
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bb6ac19d/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
new file mode 100644
index 0000000..2d14e93
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.usergrid.rest.management.organizations.applications.imports;
+
+
+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;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriInfo;
+
+import org.springframework.beans.factory.annotation.Autowired;
+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.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;
+
+
+@Component("org.apache.usergrid.rest.management.organizations.applications.imports.FileIncludesResource")
+@Scope("prototype")
+@Produces(MediaType.APPLICATION_JSON)
+public class FileIncludesResource extends AbstractContextResource {
+
+
+ @Autowired
+ protected ImportService importService;
+
+ private ApplicationInfo application;
+ private UUID importId;
+
+ /**
+ * Override our service manager factory so that we get entities from the root management app
+ */
+ public FileIncludesResource() {
+ //override the services management app
+
+ }
+
+
+ public FileIncludesResource init( final ApplicationInfo application, final UUID importId){
+ this.application = application;
+ this.importId = importId;
+ return this;
+ }
+
+
+
+ @GET
+ public JSONWithPadding getFileIncludes( @Context UriInfo ui, @QueryParam( "cursor" ) String cursor )
+ throws Exception {
+
+
+ final Results importResults = importService.getFileImports( application.getId(), importId, cursor );
+
+ if(importResults == null){
+ throw new EntityNotFoundException( "could not load import results" );
+ }
+
+ ApiResponse response = createApiResponse();
+
+
+ response.setAction( "get" );
+ response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
+ response.setParams( ui.getQueryParameters() );
+
+
+ response.withResults( importResults );
+
+ return new JSONWithPadding( response );
+
+ }
+
+ @GET
+ @Path( RootResource.ENTITY_ID_PATH )
+ public JSONWithPadding getFileIncludeById( @Context UriInfo ui, @PathParam( "entityId" ) PathSegment entityId )
+ throws Exception {
+
+ final UUID fileIncludeId = UUID.fromString( entityId.getPath() );
+ final FileImport importEntity = importService.getFileImport( application.getId(), importId, fileIncludeId );
+
+ if(importEntity == null){
+ throw new EntityNotFoundException( "could not find import with uuid " + importId );
+ }
+
+ ApiResponse response = createApiResponse();
+
+
+ response.setAction( "get" );
+ response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
+ response.setParams( ui.getQueryParameters() );
+
+
+ response.setEntities( Collections.<Entity>singletonList( importEntity ) );
+
+ return new JSONWithPadding( response );
+
+ }
+
+
+
+
+
+ @GET
+ @Path( RootResource.ENTITY_ID_PATH + "/errors" )
+ public JSONWithPadding getIncludes( @Context UriInfo ui, @PathParam( "entityId" ) PathSegment entityId )
+ throws Exception {
+
+ final UUID importId = UUID.fromString( entityId.getPath() );
+ final Import importEntity = importService.getImport( application.getId(), importId);
+
+ if(importEntity == null){
+ throw new EntityNotFoundException( "could not find import with uuid " + importId );
+ }
+
+ ApiResponse response = createApiResponse();
+
+
+ response.setAction( "get" );
+ response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
+ response.setParams( ui.getQueryParameters() );
+
+
+ response.setEntities( Collections.<Entity>singletonList( importEntity ) );
+
+ return new JSONWithPadding( response );
+
+ }
+
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bb6ac19d/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportResource.java
deleted file mode 100644
index ac1c6f5..0000000
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportResource.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.usergrid.rest.management.organizations.applications.imports;
-
-
-import com.sun.jersey.api.json.JSONWithPadding;
-import org.apache.usergrid.exception.NotImplementedException;
-import org.apache.usergrid.management.importer.ImportService;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.rest.AbstractContextResource;
-import org.apache.usergrid.rest.ApiResponse;
-import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Scope;
-import org.springframework.stereotype.Component;
-
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.UriInfo;
-import java.util.Collections;
-import java.util.UUID;
-
-
-@Component("org.apache.usergrid.rest.management.organizations.applications.imports.ImportResource")
-@Scope("prototype")
-@Produces({
- MediaType.APPLICATION_JSON,
- "application/javascript",
- "application/x-javascript",
- "text/ecmascript",
- "application/ecmascript",
- "text/jscript"
-})
-public class ImportResource extends AbstractContextResource {
-
- private static final Logger logger = LoggerFactory.getLogger( ImportResource.class );
-
- private UUID importId;
-
- @Autowired
- ImportService importService;
-
-
- public ImportResource() {
- }
-
-
- public ImportResource init( final UUID importId ) {
- this.importId = importId;
- return this;
- }
-
-
- @GET
- public JSONWithPadding get() throws Exception {
-
- logger.info( "ImportResource.get" );
-
- ApiResponse response = createApiResponse();
- response.setAction( "Get Import" );
-
- EntityManager emMgmtApp = emf.getEntityManager( emf.getManagementAppId() );
- Entity importEntity = emMgmtApp.get(importId);
-
- response.setEntities( Collections.singletonList( importEntity ));
-
- return new JSONWithPadding( response );
- }
-
-
- @DELETE
- @RequireOrganizationAccess
- public JSONWithPadding executeDelete( @Context UriInfo ui,
- @QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception {
-
- throw new NotImplementedException( "Organization delete is not allowed yet" );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bb6ac19d/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
index d74b94f..8d23bcd 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
@@ -36,50 +36,31 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.PathSegment;
-import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
-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.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
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.Import;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
-import org.apache.usergrid.persistence.index.query.Identifier;
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.applications.ServiceResource;
-import org.apache.usergrid.rest.applications.users.UserResource;
-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.services.ServiceAction;
-import org.apache.usergrid.services.ServicePayload;
-import com.amazonaws.AmazonClientException;
import com.sun.jersey.api.json.JSONWithPadding;
-import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED;
-import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
-import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-
-import static org.apache.usergrid.services.ServiceParameter.addParameter;
-
-@Component("org.apache.usergrid.rest.management.organizations.applications.ImportsResource")
-@Scope("prototype")
-@Produces(MediaType.APPLICATION_JSON)
+@Component( "org.apache.usergrid.rest.management.organizations.applications.imports.ImportsResource" )
+@Scope( "prototype" )
+@Produces( MediaType.APPLICATION_JSON )
public class ImportsResource extends AbstractContextResource {
@@ -89,6 +70,7 @@ public class ImportsResource extends AbstractContextResource {
private OrganizationInfo organization;
private ApplicationInfo application;
+
/**
* Override our service manager factory so that we get entities from the root management app
*/
@@ -98,7 +80,7 @@ public class ImportsResource extends AbstractContextResource {
}
- public ImportsResource init( final OrganizationInfo organization, final ApplicationInfo application ){
+ public ImportsResource init( final OrganizationInfo organization, final ApplicationInfo application ) {
this.organization = organization;
this.application = application;
return this;
@@ -117,15 +99,11 @@ public class ImportsResource extends AbstractContextResource {
response.setAction( "post" );
- response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
+ response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
response.setParams( ui.getQueryParameters() );
final Map<String, Object> json = ( Map<String, Object> ) readJsonToObject( body );
- UsergridAwsCredentials uac = new UsergridAwsCredentials();
-
- Map<String, String> uuidRet = new HashMap<String, String>();
-
Map<String, Object> properties;
Map<String, Object> storage_info;
// UsergridAwsCredentialsProvider uacp = new UsergridAwsCredentialsProvider();
@@ -147,8 +125,8 @@ public class ImportsResource extends AbstractContextResource {
String bucketName = ( String ) storage_info.get( "bucket_location" );
//check to make sure that access key and secret key are there.
-// uac.getAWSAccessKeyIdJson( storage_info );
-// uac.getAWSSecretKeyJson( storage_info );
+ // uac.getAWSAccessKeyIdJson( storage_info );
+ // uac.getAWSSecretKeyJson( storage_info );
if ( bucketName == null ) {
throw new NullPointerException( "Could not find field 'bucketName'" );
@@ -166,14 +144,38 @@ public class ImportsResource extends AbstractContextResource {
@GET
+ public JSONWithPadding getImports( @Context UriInfo ui, @QueryParam( "cursor" ) String cursor ) throws Exception {
+
+
+ final Results importResults = importService.getImports( application.getId(), cursor );
+
+ if ( importResults == null ) {
+ throw new EntityNotFoundException( "could not load import results" );
+ }
+
+ ApiResponse response = createApiResponse();
+
+
+ response.setAction( "get" );
+ response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
+ response.setParams( ui.getQueryParameters() );
+
+
+ response.withResults( importResults );
+
+ return new JSONWithPadding( response );
+ }
+
+
+ @GET
@Path( RootResource.ENTITY_ID_PATH )
- public JSONWithPadding addIdParameter( @Context UriInfo ui, @PathParam( "entityId" ) PathSegment entityId )
+ public JSONWithPadding getImportById( @Context UriInfo ui, @PathParam( "entityId" ) PathSegment entityId )
throws Exception {
final UUID importId = UUID.fromString( entityId.getPath() );
- final Import importEntity = importService.getImport( application.getId(), importId);
+ final Import importEntity = importService.getImport( application.getId(), importId );
- if(importEntity == null){
+ if ( importEntity == null ) {
throw new EntityNotFoundException( "could not find import with uuid " + importId );
}
@@ -181,17 +183,21 @@ public class ImportsResource extends AbstractContextResource {
response.setAction( "get" );
- response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
+ response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
response.setParams( ui.getQueryParameters() );
response.setEntities( Collections.<Entity>singletonList( importEntity ) );
return new JSONWithPadding( response );
-
}
-
-
+ @GET
+ @Path( RootResource.ENTITY_ID_PATH + "/includes" )
+ public FileIncludesResource getIncludes( @Context UriInfo ui, @PathParam( "entityId" ) PathSegment entityId )
+ throws Exception {
+ final UUID importId = UUID.fromString( entityId.getPath() );
+ return getSubResource( FileIncludesResource.class ).init( application, importId );
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bb6ac19d/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java
index 1933482..d899dc9 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.management.importer;
import org.apache.usergrid.batch.JobExecution;
import org.apache.usergrid.persistence.Results;
+import org.apache.usergrid.persistence.entities.FailedImportEntity;
import org.apache.usergrid.persistence.entities.FileImport;
import org.apache.usergrid.persistence.entities.Import;
@@ -37,6 +38,12 @@ public interface ImportService {
*/
Import schedule( final UUID applicationId, Map<String, Object> json ) throws Exception;
+ /**
+ * Get the imports results for the application
+ * @param applicationId
+ * @param cursor
+ * @return
+ */
Results getImports(final UUID applicationId, final String cursor);
/**
@@ -48,6 +55,44 @@ public interface ImportService {
Import getImport(final UUID applicationId, final UUID importId);
/**
+ * Get the results
+ *
+ * @param importId The import id to get files from
+ * @param cursor The cursor used in parsing
+ * @return
+ */
+ Results getFileImports(final UUID applicationId, final UUID importId, final String cursor);
+
+ /**
+ * Get the file import
+ * @param importId
+ * @param fileImportId
+ * @return
+ */
+ FileImport getFileImport(final UUID applicationId, final UUID importId, final UUID fileImportId);
+
+
+
+ /**
+ * Get the results of failed imports
+ *
+ * @param importId The import id to get files from
+ * @param fileImportId the fileImportId
+ * @param cursor The cursor used in parsing
+ * @return
+ */
+ Results getFailedImportEntities(final UUID applicationId, final UUID importId, final UUID fileImportId, final String cursor);
+
+ /**
+ * Get the failedimport entity from it's parentId
+ * @param importId
+ * @param fileImportId
+ * @param failedImportId
+ * @return
+ */
+ FailedImportEntity getFailedImportEntity(final UUID applicationId, final UUID importId, final UUID fileImportId, final UUID failedImportId);
+
+ /**
* Perform the import from the external resource
*/
void doImport(JobExecution jobExecution) throws Exception;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bb6ac19d/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
index 6e24264..ba72857 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
@@ -24,6 +24,7 @@ import org.apache.usergrid.batch.service.SchedulerService;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.FailedImportEntity;
import org.apache.usergrid.persistence.entities.FileImport;
import org.apache.usergrid.persistence.entities.Import;
import org.apache.usergrid.persistence.entities.JobData;
@@ -78,16 +79,7 @@ public class ImportServiceImpl implements ImportService {
}
- public SchedulerService getSch() {
- return sch;
- }
-
-
- public void setSch(final SchedulerService sch) {
- this.sch = sch;
- }
-
/**
* This schedules the main import Job.
*
@@ -146,7 +138,25 @@ public class ImportServiceImpl implements ImportService {
@Override
public Results getImports( final UUID applicationId, final String cursor ) {
- return null;
+ try {
+ final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
+
+
+ final Entity applicationEntity = getApplicationEntity( rootEm, applicationId );
+
+ Query query = new Query();
+ if ( cursor != null ) {
+ query.setCursor( cursor );
+ }
+
+ //set our entity type
+ query.setEntityType( Schema.getDefaultSchema().getEntityType( Import.class ) );
+
+ return rootEm.searchCollection( applicationEntity, APP_IMPORT_CONNECTION, query );
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to get import entity", e );
+ }
}
@@ -171,6 +181,8 @@ public class ImportServiceImpl implements ImportService {
}
+
+
private Entity getApplicationEntity(final EntityManager rootEm, final UUID applicationId) throws Exception {
final Entity entity = rootEm.get( new SimpleEntityRef( "application_info", applicationId ) );
@@ -181,6 +193,30 @@ public class ImportServiceImpl implements ImportService {
return entity;
}
+ @Override
+ public Results getFileImports(final UUID applicationId, final UUID importId, final String cursor ) {
+ return null;
+ }
+
+
+ @Override
+ public FileImport getFileImport(final UUID applicationId, final UUID importId, final UUID fileImportId ) {
+ return null;
+ }
+
+
+ @Override
+ public Results getFailedImportEntities(final UUID applicationId, final UUID importId, final UUID fileImportId, final String cursor ) {
+ return null;
+ }
+
+
+ @Override
+ public FailedImportEntity getFailedImportEntity(final UUID applicationId, final UUID importId, final UUID fileImportId,
+ final UUID failedImportId ) {
+ return null;
+ }
+
/**
* This schedules the sub FileImport Job
@@ -383,6 +419,11 @@ public class ImportServiceImpl implements ImportService {
}
+ public void setSch(final SchedulerService sch) {
+ this.sch = sch;
+ }
+
+
/**
* This method creates sub-jobs for each file i.e. File Import Jobs.
*
[2/3] incubator-usergrid git commit: Merge branch 'two-dot-o-import'
of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into
two-dot-o-import
Posted by to...@apache.org.
Merge branch 'two-dot-o-import' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-import
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c632756f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c632756f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c632756f
Branch: refs/heads/two-dot-o-import
Commit: c632756fb88d74dafaa2d3983a167ac5bb4e1227
Parents: bb6ac19 ef2bdc0
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Feb 11 09:52:22 2015 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Feb 11 09:52:22 2015 -0700
----------------------------------------------------------------------
.../java/org/apache/usergrid/management/export/S3ExportImpl.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
[3/3] incubator-usergrid git commit: Updated resources and services
to all standard service GET/query semantics
Posted by to...@apache.org.
Updated resources and services to all standard service GET/query semantics
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/db8184c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/db8184c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/db8184c8
Branch: refs/heads/two-dot-o-import
Commit: db8184c845231a8f807249c1cd3e03b9f5f169df
Parents: c632756
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Feb 11 10:23:51 2015 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Feb 11 10:23:51 2015 -0700
----------------------------------------------------------------------
.../usergrid/persistence/index/query/Query.java | 47 ++++---
.../imports/FileErrorsResource.java | 4 +-
.../imports/FileIncludesResource.java | 26 +---
.../applications/imports/ImportsResource.java | 4 +-
.../management/importer/FileImportTracker.java | 3 +
.../management/importer/ImportService.java | 33 +++--
.../management/importer/ImportServiceImpl.java | 129 ++++++++++++++++---
7 files changed, 172 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db8184c8/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
index 414061d..da68772 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
@@ -116,12 +116,12 @@ public class Query {
public Query( Query q ) {
if ( q != null ) {
type = q.type;
- sortPredicates = q.sortPredicates != null
+ sortPredicates = q.sortPredicates != null
? new ArrayList<SortPredicate>( q.sortPredicates ) : null;
startResult = q.startResult;
cursor = q.cursor;
limit = q.limit;
- selectAssignments = q.selectAssignments != null
+ selectAssignments = q.selectAssignments != null
? new LinkedHashMap<String, String>( q.selectAssignments ) : null;
mergeSelectResults = q.mergeSelectResults;
//level = q.level;
@@ -134,9 +134,9 @@ public class Query {
resolution = q.resolution;
pad = q.pad;
rootOperand = q.rootOperand;
- identifiers = q.identifiers != null
+ identifiers = q.identifiers != null
? new ArrayList<Identifier>( q.identifiers ) : null;
- counterFilters = q.counterFilters != null
+ counterFilters = q.counterFilters != null
? new ArrayList<CounterFilterPredicate>( q.counterFilters ) : null;
collection = q.collection;
}
@@ -151,8 +151,8 @@ public class Query {
//we have a root operand. Translate our AST into an ES search
if ( getRootOperand() != null ) {
- // In the case of geo only queries, this will return null into the query builder.
- // Once we start using tiles, we won't need this check any longer, since a geo query
+ // In the case of geo only queries, this will return null into the query builder.
+ // Once we start using tiles, we won't need this check any longer, since a geo query
// will return a tile query + post filter
QueryVisitor v = new EsQueryVistor();
@@ -168,11 +168,11 @@ public class Query {
}
- // Add our filter for context to our query for fast execution.
+ // Add our filter for context to our query for fast execution.
// Fast because it utilizes bitsets internally. See this post for more detail.
// http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/
- // TODO evaluate performance when it's an all query.
+ // TODO evaluate performance when it's an all query.
// Do we need to put the context term first for performance?
if ( queryBuilder != null ) {
queryBuilder = QueryBuilders.boolQuery().must( queryBuilder ).must( QueryBuilders
@@ -200,12 +200,27 @@ public class Query {
throw new RuntimeException( "Error building ElasticSearch query", ex );
}
filterBuilder = v.getFilterBuilder();
- }
+ }
- return filterBuilder;
+ return filterBuilder;
}
+ /**
+ * Create a query instance from the QL. If the string is null, return an empty query
+ * @param ql
+ * @return
+ */
+ public static Query fromQLNullSafe(final String ql){
+ final Query query = fromQL(ql);
+
+ if(query != null){
+ return query;
+ }
+
+ return new Query();
+ }
+
public static Query fromQL( String ql ) throws QueryParseException {
if ( StringUtils.isEmpty(ql) ) {
return null;
@@ -215,8 +230,8 @@ public class Query {
ql = ql.trim();
String qlt = ql.toLowerCase();
- if ( !qlt.startsWith( "select" )
- && !qlt.startsWith( "insert" )
+ if ( !qlt.startsWith( "select" )
+ && !qlt.startsWith( "insert" )
&& !qlt.startsWith( "update" ) && !qlt.startsWith( "delete" ) ) {
if ( qlt.startsWith( "order by" ) ) {
@@ -278,7 +293,7 @@ public class Query {
}
- public static Query fromQueryParams( Map<String, List<String>> params )
+ public static Query fromQueryParams( Map<String, List<String>> params )
throws QueryParseException {
Query q = null;
CounterResolution resolution = null;
@@ -636,7 +651,7 @@ public class Query {
for ( SortPredicate s : sortPredicates ) {
if ( s.getPropertyName().equals( sort.getPropertyName() ) ) {
- throw new QueryParseException( String.format(
+ throw new QueryParseException( String.format(
"Attempted to set sort order for %s more than once", s.getPropertyName() ) );
}
}
@@ -687,7 +702,7 @@ public class Query {
for ( SortPredicate s : sortPredicates ) {
if ( s.getPropertyName().equals( propertyName ) ) {
logger.error(
- "Attempted to set sort order for " + s.getPropertyName()
+ "Attempted to set sort order for " + s.getPropertyName()
+ " more than once, discarding..." );
return this;
}
@@ -1110,7 +1125,7 @@ public class Query {
private final Query.SortDirection direction;
- public SortPredicate(@JsonProperty("propertyName") String propertyName,
+ public SortPredicate(@JsonProperty("propertyName") String propertyName,
@JsonProperty("direction") Query.SortDirection direction ) {
if ( propertyName == null ) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db8184c8/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
index 552b3b5..a72a8f0 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
@@ -82,12 +82,12 @@ public class FileErrorsResource extends AbstractContextResource {
@GET
- public JSONWithPadding getFileIncludes( @Context UriInfo ui, @QueryParam( "cursor" ) String cursor )
+ public JSONWithPadding getFileIncludes( @Context UriInfo ui, @QueryParam( "ql" ) String query, @QueryParam( "cursor" ) String cursor )
throws Exception {
final Results importResults = importService.getFailedImportEntities( application.getId(), importId,
- importFileId, cursor );
+ importFileId, query, cursor );
if(importResults == null){
throw new EntityNotFoundException( "could not load import results" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db8184c8/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
index 2d14e93..c0cfe79 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
@@ -89,11 +89,11 @@ public class FileIncludesResource extends AbstractContextResource {
@GET
- public JSONWithPadding getFileIncludes( @Context UriInfo ui, @QueryParam( "cursor" ) String cursor )
+ public JSONWithPadding getFileIncludes( @Context UriInfo ui, @QueryParam( "ql" ) String query, @QueryParam( "cursor" ) String cursor )
throws Exception {
- final Results importResults = importService.getFileImports( application.getId(), importId, cursor );
+ final Results importResults = importService.getFileImports( application.getId(), importId, query, cursor );
if(importResults == null){
throw new EntityNotFoundException( "could not load import results" );
@@ -145,27 +145,11 @@ public class FileIncludesResource extends AbstractContextResource {
@GET
@Path( RootResource.ENTITY_ID_PATH + "/errors" )
- public JSONWithPadding getIncludes( @Context UriInfo ui, @PathParam( "entityId" ) PathSegment entityId )
+ public FileErrorsResource getIncludes( @Context UriInfo ui, @PathParam( "entityId" ) PathSegment entityId )
throws Exception {
- final UUID importId = UUID.fromString( entityId.getPath() );
- final Import importEntity = importService.getImport( application.getId(), importId);
-
- if(importEntity == null){
- throw new EntityNotFoundException( "could not find import with uuid " + importId );
- }
-
- ApiResponse response = createApiResponse();
-
-
- response.setAction( "get" );
- response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
- response.setParams( ui.getQueryParameters() );
-
-
- response.setEntities( Collections.<Entity>singletonList( importEntity ) );
-
- return new JSONWithPadding( response );
+ final UUID fileImportId = UUID.fromString( entityId.getPath() );
+ return getSubResource( FileErrorsResource.class ).init( application, importId,fileImportId );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db8184c8/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
index 8d23bcd..86bf278 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
@@ -144,10 +144,10 @@ public class ImportsResource extends AbstractContextResource {
@GET
- public JSONWithPadding getImports( @Context UriInfo ui, @QueryParam( "cursor" ) String cursor ) throws Exception {
+ public JSONWithPadding getImports( @Context UriInfo ui, @QueryParam( "ql" ) String query, @QueryParam( "cursor" ) String cursor ) throws Exception {
- final Results importResults = importService.getImports( application.getId(), cursor );
+ final Results importResults = importService.getImports( application.getId(), query, cursor );
if ( importResults == null ) {
throw new EntityNotFoundException( "could not load import results" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db8184c8/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java
index be2f72b..726bceb 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java
@@ -43,6 +43,9 @@ public class FileImportTracker {
private static final String ERROR_MESSAGE =
"Failed to import some data. See the import counters and errors.";
+ /**
+ * Connection name to log individual errors
+ */
public static final String ERRORS_CONNECTION_NAME = "errors";
private final AtomicLong entitiesWritten = new AtomicLong( 0 );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db8184c8/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java
index d899dc9..d63c076 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportService.java
@@ -41,10 +41,11 @@ public interface ImportService {
/**
* Get the imports results for the application
* @param applicationId
- * @param cursor
+ * @param ql The query executed (nullable)
+ * @param cursor The cursor passed (nullable)
* @return
*/
- Results getImports(final UUID applicationId, final String cursor);
+ Results getImports(final UUID applicationId, final String ql, final String cursor);
/**
* Get the import
@@ -57,34 +58,38 @@ public interface ImportService {
/**
* Get the results
*
+ * @param applicationId The applicationId
* @param importId The import id to get files from
- * @param cursor The cursor used in parsing
- * @return
+ * @param ql The query executed (nullable)
+ * @param cursor The cursor passed (nullable)
*/
- Results getFileImports(final UUID applicationId, final UUID importId, final String cursor);
+ Results getFileImports(final UUID applicationId, final UUID importId, final String ql, final String cursor);
/**
- * Get the file import
- * @param importId
- * @param fileImportId
- * @return
+ * Get the results
+ *
+ * @param applicationId The applicationId
+ * @param importId The import id to get files from
+ *
+ * @return The FileImport
*/
FileImport getFileImport(final UUID applicationId, final UUID importId, final UUID fileImportId);
-
/**
* Get the results of failed imports
*
+ *
+ * @param applicationId The applicationId
* @param importId The import id to get files from
- * @param fileImportId the fileImportId
- * @param cursor The cursor used in parsing
- * @return
+ * @param ql The query executed (nullable)
+ * @param cursor The cursor passed (nullable)
*/
- Results getFailedImportEntities(final UUID applicationId, final UUID importId, final UUID fileImportId, final String cursor);
+ Results getFailedImportEntities(final UUID applicationId, final UUID importId, final UUID fileImportId, final String ql, final String cursor);
/**
* Get the failedimport entity from it's parentId
+ * @param applicationId
* @param importId
* @param fileImportId
* @param failedImportId
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db8184c8/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
index ba72857..f35e6f2 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
@@ -45,6 +45,7 @@ import rx.functions.Func1;
import rx.functions.Func2;
import rx.schedulers.Schedulers;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import java.io.File;
import java.util.*;
@@ -59,9 +60,9 @@ public class ImportServiceImpl implements ImportService {
public static final int HEARTBEAT_COUNT = 50;
public static final String APP_IMPORT_CONNECTION ="imports";
+ public static final String IMPORT_FILE_INCLUDES_CONNECTION = "includes";
private static final Logger logger = LoggerFactory.getLogger(ImportServiceImpl.class);
- public static final String IMPORT_FILE_INCLUDES = "includes";
int MAX_FILE_IMPORTS = 1000; // max number of file import jobs / import job
@@ -137,17 +138,17 @@ public class ImportServiceImpl implements ImportService {
@Override
- public Results getImports( final UUID applicationId, final String cursor ) {
+ public Results getImports( final UUID applicationId, @Nullable final String ql, @Nullable final String cursor ) {
+ Preconditions.checkNotNull( applicationId, "applicationId must be specified" );
+
try {
final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
final Entity applicationEntity = getApplicationEntity( rootEm, applicationId );
- Query query = new Query();
- if ( cursor != null ) {
- query.setCursor( cursor );
- }
+ Query query = Query.fromQLNullSafe( ql );
+ query.setCursor( cursor );
//set our entity type
query.setEntityType( Schema.getDefaultSchema().getEntityType( Import.class ) );
@@ -162,6 +163,9 @@ public class ImportServiceImpl implements ImportService {
@Override
public Import getImport( final UUID applicationId, final UUID importId ) {
+ Preconditions.checkNotNull( applicationId, "applicationId must be specified" );
+ Preconditions.checkNotNull( importId, "importId must be specified" );
+
try {
final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
@@ -181,8 +185,6 @@ public class ImportServiceImpl implements ImportService {
}
-
-
private Entity getApplicationEntity(final EntityManager rootEm, final UUID applicationId) throws Exception {
final Entity entity = rootEm.get( new SimpleEntityRef( "application_info", applicationId ) );
@@ -194,27 +196,115 @@ public class ImportServiceImpl implements ImportService {
}
@Override
- public Results getFileImports(final UUID applicationId, final UUID importId, final String cursor ) {
- return null;
+ public Results getFileImports(final UUID applicationId, final UUID importId, @Nullable final String ql, @Nullable final String cursor ) {
+
+ Preconditions.checkNotNull( applicationId, "applicationId must be specified" );
+ Preconditions.checkNotNull( importId, "importId must be specified" );
+
+ try {
+ final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
+
+
+ final Import importEntity = getImport( applicationId, importId );
+
+ Query query = Query.fromQLNullSafe( ql );
+ query.setCursor( cursor );
+
+ //set our entity type
+ query.setEntityType( Schema.getDefaultSchema().getEntityType( Import.class ) );
+
+ return rootEm.searchCollection( importEntity, IMPORT_FILE_INCLUDES_CONNECTION, query );
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to get import entity", e );
+ }
+
}
@Override
public FileImport getFileImport(final UUID applicationId, final UUID importId, final UUID fileImportId ) {
- return null;
+ try {
+ final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
+
+
+ final Import importEntity = getImport( applicationId, importId );
+
+ if ( importEntity == null ) {
+ throw new EntityNotFoundException( "Import not found with id " + importId );
+ }
+
+
+ final FileImport fileImport = rootEm.get( importId, FileImport.class );
+
+
+ // check if it's on the path
+ if ( !rootEm.isConnectionMember( importEntity, APP_IMPORT_CONNECTION, fileImport ) ) {
+ return null;
+ }
+
+ return fileImport;
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to load file import", e );
+ }
}
@Override
- public Results getFailedImportEntities(final UUID applicationId, final UUID importId, final UUID fileImportId, final String cursor ) {
- return null;
+ public Results getFailedImportEntities(final UUID applicationId, final UUID importId, final UUID fileImportId, @Nullable final String ql, @Nullable final String cursor ) {
+
+ Preconditions.checkNotNull( applicationId, "applicationId must be specified" );
+ Preconditions.checkNotNull( importId, "importId must be specified" );
+ Preconditions.checkNotNull( fileImportId, "fileImportId must be specified" );
+
+ try {
+ final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
+
+
+ final FileImport importEntity = getFileImport( applicationId, importId, fileImportId );
+
+ Query query = Query.fromQLNullSafe( ql );
+ query.setCursor( cursor );
+
+ //set our entity type
+ query.setEntityType( Schema.getDefaultSchema().getEntityType( FailedImportEntity.class ) );
+
+ return rootEm.searchCollection( importEntity, FileImportTracker.ERRORS_CONNECTION_NAME, query );
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to get import entity", e );
+ }
}
@Override
public FailedImportEntity getFailedImportEntity(final UUID applicationId, final UUID importId, final UUID fileImportId,
final UUID failedImportId ) {
- return null;
+ try {
+ final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
+
+
+ final FileImport importEntity = getFileImport( applicationId, importId, fileImportId );
+
+ if ( importEntity == null ) {
+ throw new EntityNotFoundException( "Import not found with id " + importId );
+ }
+
+
+ final FailedImportEntity fileImport = rootEm.get( importId, FailedImportEntity.class );
+
+
+ // check if it's on the path
+ if ( !rootEm.isConnectionMember( importEntity, FileImportTracker.ERRORS_CONNECTION_NAME, fileImport ) ) {
+ return null;
+ }
+
+ return fileImport;
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to load file import", e );
+ }
}
@@ -248,7 +338,7 @@ public class ImportServiceImpl implements ImportService {
try {
// create a connection between the main import job and the sub FileImport Job
- emManagementApp.createConnection(importEntity, IMPORT_FILE_INCLUDES, fileImport);
+ emManagementApp.createConnection(importEntity, IMPORT_FILE_INCLUDES_CONNECTION, fileImport);
logger.debug("Created connection from {}:{} to {}:{}",
new Object[] {
@@ -284,11 +374,12 @@ public class ImportServiceImpl implements ImportService {
try {
EntityManager emMgmtApp = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
- Query query = Query.fromQL("select *");
+ Query query = Query.fromQL( "select *" );
query.setEntityType("file_import");
- query.setConnectionType( IMPORT_FILE_INCLUDES );
+ query.setConnectionType( IMPORT_FILE_INCLUDES_CONNECTION );
query.setLimit(MAX_FILE_IMPORTS);
+ //TODO, this won't work with more than 100 files
Results entities = emMgmtApp.searchConnectedEntities( importRoot, query );
return entities.size();
@@ -638,7 +729,7 @@ public class ImportServiceImpl implements ImportService {
// get parent import job of this file import job
Results importJobResults =
- emManagementApp.getConnectingEntities( fileImport, IMPORT_FILE_INCLUDES, null, Level.ALL_PROPERTIES );
+ emManagementApp.getConnectingEntities( fileImport, IMPORT_FILE_INCLUDES_CONNECTION, null, Level.ALL_PROPERTIES );
List<Entity> importEntities = importJobResults.getEntities();
UUID importId = importEntities.get( 0 ).getUuid();
Import importEntity = emManagementApp.get( importId, Import.class );
@@ -649,7 +740,7 @@ public class ImportServiceImpl implements ImportService {
EntityManager emMgmtApp = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
Query query = Query.fromQL("select *");
query.setEntityType("file_import");
- query.setConnectionType( IMPORT_FILE_INCLUDES );
+ query.setConnectionType( IMPORT_FILE_INCLUDES_CONNECTION );
query.setLimit(MAX_FILE_IMPORTS);
Results entities = emMgmtApp.searchConnectedEntities(importEntity, query);