Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SASC
sentinel-legacy
Commits
877cb631
Commit
877cb631
authored
Jul 06, 2015
by
bow
Browse files
Refactor Processors base classes
parent
b4a35669
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/main/scala/nl/lumc/sasc/sentinel/api/RunsController.scala
View file @
877cb631
...
...
@@ -17,17 +17,19 @@
package
nl.lumc.sasc.sentinel.api
import
java.io.File
import
scala.util.
{
Failure
,
Success
,
Try
}
import
scala.util.
{
Failure
,
Success
}
import
org.scalatra._
import
org.scalatra.swagger._
import
org.scalatra.servlet.
{
FileItem
,
FileUploadSupport
,
MultipartConfig
,
SizeConstraintExceededException
}
import
org.scalatra.servlet.
{
FileUploadSupport
,
MultipartConfig
,
SizeConstraintExceededException
}
import
nl.lumc.sasc.sentinel.
{
AllowedPipelineParams
,
HeaderApiKey
,
Pipeline
}
import
nl.lumc.sasc.sentinel.api.auth.AuthenticationSupport
import
nl.lumc.sasc.sentinel.db._
import
nl.lumc.sasc.sentinel.processors.gentrap.GentrapV04InputProcessor
import
nl.lumc.sasc.sentinel.processors.plain.PlainInputProcessor
import
nl.lumc.sasc.sentinel.processors.gentrap.GentrapV04RunsProcessor
import
nl.lumc.sasc.sentinel.processors.plain.PlainRunsProcessor
import
nl.lumc.sasc.sentinel.processors.GenericRunsProcessor
import
nl.lumc.sasc.sentinel.settings._
import
nl.lumc.sasc.sentinel.models._
import
nl.lumc.sasc.sentinel.utils._
...
...
@@ -50,19 +52,16 @@ class RunsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
protected
val
applicationDescription
:
String
=
"Submission and retrieval of run summaries"
/** Adapter for connecting to run collections. */
val
runs
=
new
RunsAdapter
{
val
mongo
=
self
.
mongo
def
processRun
(
fi
:
FileItem
,
user
:
User
,
pipeline
:
Pipeline.Value
)
=
Try
(
throw
new
NotImplementedError
)
}
val
runs
=
new
GenericRunsProcessor
(
mongo
)
/** Adapter for connecting to users collection. */
val
users
=
new
UsersAdapter
{
val
mongo
=
self
.
mongo
}
/** Adapter for connecting to the plain summary collections. */
val
plain
=
new
Plain
Input
Processor
(
mongo
)
val
plain
=
new
Plain
Runs
Processor
(
mongo
)
/** Adapter for connecting to the gentrap summary collections. */
val
gentrap
=
new
GentrapV04
Input
Processor
(
mongo
)
val
gentrap
=
new
GentrapV04
Runs
Processor
(
mongo
)
/** Set maximum allowed file upload size. */
configureMultipartHandling
(
MultipartConfig
(
maxFileSize
=
Some
(
MaxRunSummarySize
)))
...
...
src/main/scala/nl/lumc/sasc/sentinel/db/UnitsAdapter.scala
View file @
877cb631
...
...
@@ -21,6 +21,7 @@ import com.novus.salat._
import
com.novus.salat.global._
import
nl.lumc.sasc.sentinel.models.
{
BaseLibRecord
,
BaseSampleRecord
}
import
nl.lumc.sasc.sentinel.processors.RunsProcessor
/**
* Trait for storing samples and libraries from run summaries.
...
...
@@ -28,10 +29,7 @@ import nl.lumc.sasc.sentinel.models.{ BaseLibRecord, BaseSampleRecord }
* @tparam S Subclass of [[nl.lumc.sasc.sentinel.models.BaseSampleRecord]] representing a sample run by a pipeline.
* @tparam L Subclass of [[nl.lumc.sasc.sentinel.models.BaseLibRecord]] representing a library run by a pipeline.
*/
trait
UnitsAdapter
[
S
<:
BaseSampleRecord
,
L
<:
BaseLibRecord
]
extends
MongodbConnector
{
this:
RunsAdapter
=>
/** Name of the pipeline that produces the run summary file. */
def
pipelineName
:
String
trait
UnitsAdapter
[
S
<:
BaseSampleRecord
,
L
<:
BaseLibRecord
]
extends
MongodbConnector
{
this:
RunsProcessor
=>
/** Collection for the samples. */
private
lazy
val
samplesColl
=
mongo
.
db
(
collectionNames
.
pipelineSamples
(
pipelineName
))
...
...
src/main/scala/nl/lumc/sasc/sentinel/processors/GenericRunsProcessor.scala
0 → 100644
View file @
877cb631
/*
* Copyright (c) 2015 Leiden University Medical Center and contributors
* (see AUTHORS.md file for details).
*
* 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
nl.lumc.sasc.sentinel.processors
import
scala.util.Try
import
org.scalatra.servlet.FileItem
import
nl.lumc.sasc.sentinel.Pipeline
import
nl.lumc.sasc.sentinel.db.MongodbAccessObject
import
nl.lumc.sasc.sentinel.models._
/**
* Input processor that does not process incoming runs. Rather, it is used for querying run data of any pipelines.
*/
class
GenericRunsProcessor
(
mongo
:
MongodbAccessObject
)
extends
RunsProcessor
(
mongo
)
{
def
pipelineName
=
"generic"
def
processRun
(
fi
:
FileItem
,
user
:
User
,
pipeline
:
Pipeline.Value
)
=
Try
(
throw
new
NotImplementedError
)
}
src/main/scala/nl/lumc/sasc/sentinel/processors/Processor.scala
0 → 100644
View file @
877cb631
/*
* Copyright (c) 2015 Leiden University Medical Center and contributors
* (see AUTHORS.md file for details).
*
* 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
nl.lumc.sasc.sentinel.processors
import
nl.lumc.sasc.sentinel.db.
{
MongodbAccessObject
,
MongodbConnector
}
/** Base trait for defining processors. */
trait
Processor
extends
MongodbConnector
{
/** Run summary pipeline name. */
def
pipelineName
:
String
}
src/main/scala/nl/lumc/sasc/sentinel/
db/RunsAdapte
r.scala
→
src/main/scala/nl/lumc/sasc/sentinel/
processors/RunsProcesso
r.scala
View file @
877cb631
...
...
@@ -14,23 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl.lumc.sasc.sentinel.
db
package
nl.lumc.sasc.sentinel.
processors
import
java.io.ByteArrayInputStream
import
scala.util.Try
import
com.mongodb.casbah.gridfs.GridFSDBFile
import
com.mongodb.casbah.Imports._
import
com.mongodb.casbah.gridfs.GridFSDBFile
import
com.novus.salat._
import
com.novus.salat.global._
import
org.scalatra.servlet.FileItem
import
nl.lumc.sasc.sentinel.Pipeline
import
nl.lumc.sasc.sentinel.db.MongodbAccessObject
import
nl.lumc.sasc.sentinel.models.
{
PipelineStats
,
RunRecord
,
User
}
import
nl.lumc.sasc.sentinel.utils.
{
DuplicateFileException
,
calcMd5
,
getUtcTimeNow
}
import
org.scalatra.servlet.FileItem
import
scala.util.Try
/** Trait for processing and storing run summary files to a run records collection */
trait
RunsAdapter
extends
MongodbConnector
{
/**
* Base class for processing run summary files.
*/
abstract
class
RunsProcessor
(
protected
val
mongo
:
MongodbAccessObject
)
extends
Processor
{
/**
* Processes and stores the given uploaded file to the run records collection.
...
...
src/main/scala/nl/lumc/sasc/sentinel/processors/
Output
Processor.scala
→
src/main/scala/nl/lumc/sasc/sentinel/processors/
Stats
Processor.scala
View file @
877cb631
...
...
@@ -23,20 +23,17 @@ import com.novus.salat._
import
com.novus.salat.global._
import
com.mongodb.casbah.Imports._
import
nl.lumc.sasc.sentinel.
{
AccLevel
,
LibType
,
SeqQcPhase
}
import
nl.lumc.sasc.sentinel.db.Mongodb
Conn
ect
or
import
nl.lumc.sasc.sentinel.
{
AccLevel
,
LibType
}
import
nl.lumc.sasc.sentinel.db.Mongodb
AccessObj
ect
import
nl.lumc.sasc.sentinel.models.
{
SeqStatsAggr
,
User
}
/**
* Base
trait
that provides support for querying and aggregating
metr
ics for a pipeline.
* Base
class
that provides support for querying and aggregating
statist
ics for a pipeline.
*/
tra
i
t
OutputProcessor
extends
MongodbConnect
or
{
abs
tra
c
t
class
StatsProcessor
(
protected
val
mongo
:
MongodbAccessObject
)
extends
Process
or
{
// TODO: refactor functions in here ~ we can do with less duplication
/** Name of the pipeline that produces the metrics to query. */
def
pipelineName
:
String
/** Name of the unit attribute that denotes whether it comes from a paired-end library or not. */
protected
implicit
val
pairAttrib
=
"isPaired"
...
...
src/main/scala/nl/lumc/sasc/sentinel/processors/gentrap/Gentrap
Output
Processor.scala
→
src/main/scala/nl/lumc/sasc/sentinel/processors/gentrap/Gentrap
Stats
Processor.scala
View file @
877cb631
...
...
@@ -18,14 +18,14 @@ package nl.lumc.sasc.sentinel.processors.gentrap
import
nl.lumc.sasc.sentinel.db.MongodbAccessObject
import
nl.lumc.sasc.sentinel.models._
import
nl.lumc.sasc.sentinel.processors.
Output
Processor
import
nl.lumc.sasc.sentinel.processors.
Stats
Processor
/**
* Output processor for Gentrap endpoints.
*
* @param mongo MongoDB database access object.
*/
class
Gentrap
Output
Processor
(
protected
val
mongo
:
MongodbAccessObject
)
extends
Output
Processor
{
class
Gentrap
Stats
Processor
(
mongo
:
MongodbAccessObject
)
extends
Stats
Processor
(
mongo
)
{
def
pipelineName
=
"gentrap"
...
...
src/main/scala/nl/lumc/sasc/sentinel/processors/gentrap/GentrapV04
Input
Processor.scala
→
src/main/scala/nl/lumc/sasc/sentinel/processors/gentrap/GentrapV04
Runs
Processor.scala
View file @
877cb631
...
...
@@ -16,6 +16,8 @@
*/
package
nl.lumc.sasc.sentinel.processors.gentrap
import
nl.lumc.sasc.sentinel.processors.RunsProcessor
import
scala.util.Try
import
org.apache.commons.io.FilenameUtils.
{
getExtension
,
getName
}
...
...
@@ -37,9 +39,9 @@ import nl.lumc.sasc.sentinel.validation.ValidationAdapter
*
* @param mongo MongoDB database access object.
*/
class
GentrapV04
Input
Processor
(
protected
val
mongo
:
MongodbAccessObject
)
extends
UnitsAdapter
[
GentrapSampleRecord
,
GentrapLibRecord
]
with
Run
sAdapter
class
GentrapV04
Runs
Processor
(
mongo
:
MongodbAccessObject
)
extends
RunsProcessor
(
mongo
)
with
Unit
sAdapter
[
GentrapSampleRecord
,
GentrapLibRecord
]
with
ValidationAdapter
with
ReferencesAdapter
with
AnnotationsAdapter
{
...
...
src/main/scala/nl/lumc/sasc/sentinel/processors/plain/Plain
Input
Processor.scala
→
src/main/scala/nl/lumc/sasc/sentinel/processors/plain/Plain
Runs
Processor.scala
View file @
877cb631
...
...
@@ -19,6 +19,7 @@ package nl.lumc.sasc.sentinel.processors.plain
import
java.time.Clock
import
java.util.Date
import
nl.lumc.sasc.sentinel.models.
{
RunRecord
,
User
}
import
nl.lumc.sasc.sentinel.processors.RunsProcessor
import
scala.util.Try
import
org.scalatra.servlet.FileItem
...
...
@@ -37,10 +38,11 @@ import nl.lumc.sasc.sentinel.validation.ValidationAdapter
*
* @param mongo MongoDB database access object.
*/
class
PlainInputProcessor
(
protected
val
mongo
:
MongodbAccessObject
)
extends
RunsAdapter
class
PlainRunsProcessor
(
mongo
:
MongodbAccessObject
)
extends
RunsProcessor
(
mongo
)
with
ValidationAdapter
{
def
pipelineName
=
"plain"
val
validator
=
createValidator
(
"/schemas/plain.json"
)
def
processRun
(
fi
:
FileItem
,
user
:
User
,
pipeline
:
Pipeline.Value
)
=
...
...
src/test/scala/nl/lumc/sasc/sentinel/processors/gentrap/GentrapValidationSpec.scala
View file @
877cb631
...
...
@@ -28,7 +28,7 @@ class GentrapValidationSpec extends Specification with JsonLoader with Mockito {
"Support for the 'gentrap' pipeline"
should
{
br
val
ipv04
=
new
GentrapV04
Input
Processor
(
mongo
)
val
ipv04
=
new
GentrapV04
Runs
Processor
(
mongo
)
"exclude non-gentrap summary files"
in
{
val
summary
=
loadJson
(
"/schema_examples/plain.json"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment