Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Commit

Permalink
Implementing the aggregated HarvestableCollectionLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbernhardt committed Jul 12, 2012
1 parent fc6e376 commit 3f2d51c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/plugins/CorePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CorePlugin(app: Application) extends CultureHubPlugin(app) {

val pluginKey: String = "core"

private val dataSetHarvestableCollectionManager = new DataSetHarvestCollectionLookup
private val dataSetHarvestCollectionLookup = new DataSetHarvestCollectionLookup

override def enabled: Boolean = true

Expand Down Expand Up @@ -64,5 +64,5 @@ class CorePlugin(app: Application) extends CultureHubPlugin(app) {
)
)

override def getHarvestableCollectionManagers: Seq[HarvestCollectionLookup] = Seq(dataSetHarvestableCollectionManager)
override def getHarvestCollectionLookups: Seq[HarvestCollectionLookup] = Seq(dataSetHarvestCollectionLookup)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ case class VirtualCollection(_id: ObjectId = new ObjectId,

// ~~~ harvesting
def getRecords(metadataFormat: String, position: Int, limit: Int): (List[MetadataItem], Long) = {
val references = VirtualCollection.children.find(MongoDBObject("parentId" -> _id, "validOutputFormats" -> metadataFormat) ++ ("idx" $gt position)).sort(MongoDBObject("idx" -> 1)).limit(limit)
val totalSize = VirtualCollection.children.count(MongoDBObject("parentId" -> _id, "validOutputFormats" -> metadataFormat) ++ ("idx" $gt position))
val references = VirtualCollection.children.find(MongoDBObject("parentId" -> _id) ++ ("invalidTargetSchemas" $ne metadataFormat) ++ ("index" $gt position)).sort(MongoDBObject("index" -> 1)).limit(limit)
val totalSize = VirtualCollection.children.count(MongoDBObject("parentId" -> _id) ++ ("invalidTargetSchemas" $ne metadataFormat) ++ ("index" $gt position))
val records = references.toList.groupBy(_.collection).map {
grouped =>
val cache = MetadataCache.get(orgId, grouped._1, ITEM_TYPE_MDR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CustomHarvestCollectionPlugin(app: Application) extends CultureHubPlugin(a

val pluginKey: String = "customHarvestCollection"

private val customHarvestCollectionHarvestableCollectionManager = new CustomHarvestCollectionHarvestCollectionLookup
private val customHarvestCollectionHarvestCollectionLookup = new CustomHarvestCollectionHarvestCollectionLookup


override def onApplicationStart() {
Expand Down Expand Up @@ -85,6 +85,6 @@ class CustomHarvestCollectionPlugin(app: Application) extends CultureHubPlugin(a
)
)

override def getHarvestableCollectionManagers: Seq[HarvestCollectionLookup] = Seq(customHarvestCollectionHarvestableCollectionManager)
override def getHarvestCollectionLookups: Seq[HarvestCollectionLookup] = Seq(customHarvestCollectionHarvestCollectionLookup)

}
2 changes: 1 addition & 1 deletion web-core/app/core/CultureHubPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class CultureHubPlugin(app: Application) extends play.api.Plugin {
filter(e => !e.membersOnly || (e.membersOnly && isMember && (e.roles.isEmpty || e.roles.map(_.key).intersect(roles).size > 0))).
map(i => i.copy(items = i.items.filter(item => item.roles.isEmpty || (!item.roles.isEmpty && item.roles.map(_.key).intersect(roles).size > 0))))

def getHarvestableCollectionManagers: Seq[HarvestCollectionLookup] = List.empty
def getHarvestCollectionLookups: Seq[HarvestCollectionLookup] = List.empty

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
package core.harvesting

import core.collection.{Harvestable}
import models.{RecordDefinition, DataSetState, DataSet}
import core.collection.Harvestable
import models.RecordDefinition
import core.CultureHubPlugin
import play.api.Play
import play.api.Play.current

/**
* Lookup mechanism for Harvestable Collections
*
* TODO in the future, each harvestable collection type should register itself against this manager along with a way to retrieve the various lookups.
* That way harvesting becomes a more modular functionality. At the moment all lookups are assembled here.
* Aggregated lookup mechanism all for Harvestable Collections
*
* @author Manuel Bernhardt <bernhardt.manuel@gmail.com>
*/

object AggregatingHarvestableCollectionLookup {

def findAllNonEmpty(orgId: String, format: Option[String], accessKey: Option[String] = None): List[Harvestable] = {
lazy val hubPlugins: List[CultureHubPlugin] = Play.application.plugins.filter(_.isInstanceOf[CultureHubPlugin]).map(_.asInstanceOf[CultureHubPlugin]).toList
lazy val harvestCollectionLookups = hubPlugins.flatMap(_.getHarvestCollectionLookups)

// TODO implement accessKey lookup
val dataSets: List[Harvestable] = {
val sets = DataSet.findAll(orgId).filterNot(_.state != DataSetState.ENABLED)
if(format.isDefined) {
sets.filter(ds => ds.getVisibleMetadataSchemas(accessKey).exists(_.prefix == format.get))
} else {
sets
}
}

dataSets
def findAllNonEmpty(orgId: String, format: Option[String], accessKey: Option[String] = None): List[Harvestable] = {
harvestCollectionLookups.flatMap(lookup => lookup.findAllNonEmpty(orgId, format, accessKey))
}

def findBySpecAndOrgId(spec: String, orgId: String): Option[Harvestable] = {
DataSet.findBySpecAndOrgId(spec, orgId)
harvestCollectionLookups.flatMap(_.findBySpecAndOrgId(spec, orgId)).headOption
}

/**
* Gets all publicly available formats out there, plus the ones available via the accessKey.
*/
def getAllMetadataFormats(orgId: String, accessKey: Option[String]): List[RecordDefinition] = {
DataSet.getAllVisibleMetadataFormats(orgId, accessKey).distinct
harvestCollectionLookups.flatMap(_.getAllMetadataFormats(orgId, accessKey))
}


Expand Down

0 comments on commit 3f2d51c

Please sign in to comment.