11package api
22
3- import java .io .{ByteArrayInputStream , InputStream , ByteArrayOutputStream }
4- import java .security .{DigestInputStream , MessageDigest }
5- import java .text .SimpleDateFormat
6- import java .util .zip .{ZipEntry , ZipOutputStream , Deflater }
7-
83import Iterators .RootCollectionIterator
9- import _root_ . util .JSONLD
4+ import util .SearchUtils
105import api .Permission .Permission
11- import org .apache .commons .codec .binary .Hex
6+ import controllers .Utils
7+ import models ._
128import play .api .Logger
139import play .api .Play .current
14- import models ._
10+ import play . api . libs . concurrent . Execution . Implicits ._
1511import play .api .libs .iteratee .Enumerator
16- import services ._
17- import play .api .libs .json ._
18- import play .api .libs .json .{JsObject , JsValue }
1912import play .api .libs .json .Json .toJson
20- import javax .inject .{ Singleton , Inject }
21- import scala .collection .mutable .ListBuffer
22- import scala .concurrent .{Future , ExecutionContext }
23- import play .api .libs .concurrent .Execution .Implicits ._
24- import scala .util .parsing .json .JSONArray
25- import scala .util .{Try , Success , Failure }
26- import java .util .{Calendar , Date }
27- import controllers .Utils
13+ import play .api .libs .json .{JsObject , JsValue , _ }
14+ import services ._
2815
16+
17+ import java .io .ByteArrayOutputStream
18+ import java .security .MessageDigest
19+ import java .util .zip .{Deflater , ZipOutputStream }
20+ import java .util .{Calendar , Date }
21+ import javax .inject .{Inject , Singleton }
2922import scala .collection .immutable .List
23+ import scala .collection .mutable .ListBuffer
24+ import scala .concurrent .{ExecutionContext , Future }
25+ import scala .util .{Failure , Success , Try }
3026
3127
3228/**
@@ -72,6 +68,13 @@ class Collections @Inject() (datasets: DatasetService,
7268 collections.addToRootSpaces(c.id, s.id)
7369 events.addSourceEvent(request.user, c.id, c.name, s.id, s.name, EventType .ADD_COLLECTION_SPACE .toString)
7470 })
71+ // index collection
72+ current.plugin[ElasticsearchPlugin ].foreach{
73+ _.index(SearchUtils .getElasticsearchObject(c))
74+ }
75+ // Add to Events Table
76+ val option_user = userService.findByIdentity(identity)
77+ events.addObjectEvent(option_user, c.id, c.name, EventType .CREATE_COLLECTION .toString)
7578 Ok (toJson(Map (" id" -> id)))
7679 }
7780 case None => Ok (toJson(Map (" status" -> " error" )))
@@ -237,15 +240,15 @@ class Collections @Inject() (datasets: DatasetService,
237240 }
238241 }
239242
240- def list (title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
241- Ok (toJson(listCollections(title, date, limit, Set [Permission ](Permission .ViewCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
243+ def list (when : Option [ String ], title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
244+ Ok (toJson(listCollections(when, title, date, limit, Set [Permission ](Permission .ViewCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
242245 }
243246
244- def listCanEdit (title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
245- Ok (toJson(listCollections(title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
247+ def listCanEdit (when : Option [ String ], title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
248+ Ok (toJson(listCollections(when, title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)))
246249 }
247250
248- def addDatasetToCollectionOptions (datasetId : UUID , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
251+ def addDatasetToCollectionOptions (when : Option [ String ], datasetId : UUID , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
249252 implicit val user = request.user
250253 var listAll = false
251254 var collectionList : List [Collection ] = List .empty
@@ -265,7 +268,7 @@ class Collections @Inject() (datasets: DatasetService,
265268 }
266269 }
267270 if (listAll) {
268- collectionList = listCollections(title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)
271+ collectionList = listCollections(when, title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false , request.user, request.user.fold(false )(_.superAdminMode), exact)
269272 }
270273 Ok (toJson(collectionList))
271274 }
@@ -274,10 +277,10 @@ class Collections @Inject() (datasets: DatasetService,
274277 collections.get(current_collections.map(_.child_collection_ids).flatten).found
275278 }
276279
277- def listPossibleParents (currentCollectionId : String , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
280+ def listPossibleParents (when : Option [ String ], currentCollectionId : String , title : Option [String ], date : Option [String ], limit : Int , exact : Boolean ) = PrivateServerAction { implicit request =>
278281 val selfAndAncestors = collections.getSelfAndAncestors(UUID (currentCollectionId))
279282 val descendants = collections.getAllDescendants(UUID (currentCollectionId)).toList
280- val allCollections = listCollections(title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false ,
283+ val allCollections = listCollections(when, title, date, limit, Set [Permission ](Permission .AddResourceToCollection , Permission .EditCollection ), false ,
281284 request.user, request.user.fold(false )(_.superAdminMode), exact)
282285 val possibleNewParents = allCollections.filter(c =>
283286 if (play.api.Play .current.plugin[services.SpaceSharingPlugin ].isDefined) {
@@ -303,29 +306,55 @@ class Collections @Inject() (datasets: DatasetService,
303306 * Returns list of collections based on parameters and permissions.
304307 * TODO this needs to be cleaned up when do permissions for adding to a resource
305308 */
306- private def listCollections (title : Option [String ], date : Option [String ], limit : Int , permission : Set [Permission ], mine : Boolean , user : Option [User ], superAdmin : Boolean , exact : Boolean ) : List [Collection ] = {
309+ private def listCollections (when : Option [ String ], title : Option [String ], date : Option [String ], limit : Int , permission : Set [Permission ], mine : Boolean , user : Option [User ], superAdmin : Boolean , exact : Boolean ) : List [Collection ] = {
307310 if (mine && user.isEmpty) return List .empty[Collection ]
308311
309- (title, date) match {
310- case (Some (t), Some (d)) => {
312+ (when, title, date) match {
313+ case (Some (w), Some (t), Some (d)) => {
314+ if (mine)
315+ collections.listUser(d, nextPage= (w== " a" ), limit, t, user, superAdmin, user.get, exact)
316+ else
317+ collections.listAccess(d, nextPage= (w== " a" ), limit, t, permission, user, superAdmin, true ,false , exact)
318+ }
319+ case (Some (w), Some (t), None ) => {
320+ if (mine)
321+ collections.listUser(limit, t, user, superAdmin, user.get, exact)
322+ else
323+ collections.listAccess(limit, t, permission, user, superAdmin, true ,false , exact)
324+ }
325+ case (Some (w), None , Some (d)) => {
326+ if (mine)
327+ collections.listUser(d, nextPage= (w== " a" ), limit, user, superAdmin, user.get)
328+ else
329+ collections.listAccess(d, nextPage= (w== " a" ), limit, permission, user, superAdmin, true ,false )
330+ }
331+ case (Some (w), None , None ) => {
332+ if (mine)
333+ collections.listUser(limit, user, superAdmin, user.get)
334+ else
335+ collections.listAccess(limit, permission, user, superAdmin, true ,false )
336+ }
337+
338+ // default when to be "after" if not present in parameters. i.e. nextPage=true
339+ case (None , Some (t), Some (d)) => {
311340 if (mine)
312341 collections.listUser(d, true , limit, t, user, superAdmin, user.get, exact)
313342 else
314343 collections.listAccess(d, true , limit, t, permission, user, superAdmin, true ,false , exact)
315344 }
316- case (Some (t), None ) => {
345+ case (None , Some (t), None ) => {
317346 if (mine)
318347 collections.listUser(limit, t, user, superAdmin, user.get, exact)
319348 else
320349 collections.listAccess(limit, t, permission, user, superAdmin, true ,false , exact)
321350 }
322- case (None , Some (d)) => {
351+ case (None , None , Some (d)) => {
323352 if (mine)
324353 collections.listUser(d, true , limit, user, superAdmin, user.get)
325354 else
326355 collections.listAccess(d, true , limit, permission, user, superAdmin, true ,false )
327356 }
328- case (None , None ) => {
357+ case (None , None , None ) => {
329358 if (mine)
330359 collections.listUser(limit, user, superAdmin, user.get)
331360 else
@@ -572,6 +601,14 @@ class Collections @Inject() (datasets: DatasetService,
572601 events.addSourceEvent(request.user, c.id, c.name, s.id, s.name, EventType .ADD_COLLECTION_SPACE .toString)
573602 }
574603
604+ // index collection
605+ current.plugin[ElasticsearchPlugin ].foreach{
606+ _.index(SearchUtils .getElasticsearchObject(c))
607+ }
608+ // Add to Events Table
609+ val option_user = userService.findByIdentity(identity)
610+ events.addObjectEvent(option_user, c.id, c.name, EventType .CREATE_COLLECTION .toString)
611+
575612 // do stuff with parent here
576613 (request.body \ " parentId" ).asOpt[String ] match {
577614 case Some (parentId) => {
0 commit comments