Last active
August 29, 2015 14:06
-
-
Save swoogles/b3316742e5b8dc233633 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class PortalMsg( | |
portalMsgIdx: Long = 0, | |
portalMsgThreadIdx: Int = 0, | |
message: Option[String] = None, | |
sentDateTime: Option[DateTime] = None, | |
readDateTime: Option[DateTime] = None, | |
sentBy: Option[Int] = None, | |
readBy: Option[Int] = None | |
) | |
case class SecureFile( | |
secureFileIdx: Long = 0, | |
subscriberIdx: Long = 0, | |
portalMsgIdx: Option[Long] = None, | |
userIdx: Long = 0, | |
fileName: String = "defaultFileName", | |
title: String = "defaultTitle", | |
description: Option[String] = None, | |
mimeType: Option[String] = None, | |
fileSizeBytes: Long = 0, | |
createdDate: Option[Date] = None, | |
file: Option[File] = None | |
) | |
// Old | |
def createPath(subFileOption:Option[SecureFile], msgOption:Option[PortalMsg]):Option[String] = { | |
for { | |
subFile <- subFileOption | |
msg <- msgOption | |
} | |
yield { | |
List(ABS_SF_PATH, | |
subFile.subscriberIdx, | |
PORTAL_MSG_THREADS_PATH, | |
msg.portalMsgThreadIdx, | |
msg.portalMsgIdx | |
).mkString(SEPARATOR) | |
} | |
} | |
//New | |
def createPath(subFile:SecureFile, msg:PortalMsg):String = { | |
List(ABS_SF_PATH, | |
subFile.subscriberIdx, | |
PORTAL_MSG_THREADS_PATH, | |
msg.portalMsgThreadIdx, | |
msg.portalMsgIdx | |
).mkString(SEPARATOR) | |
} | |
//Old - This one was only creating the path, not doing the full retrieval | |
def getPortalMsgAttachment( secureFileIdx:Long )(implicit connection:Connection) = { | |
val subFile = findById( secureFileIdx ) | |
val portalMsgIdx:Option[Long] = subFile flatMap( _.portalMsgIdx ) | |
val msg = portalMsgIdx match { | |
case Some(idx) => PortalMsgThread.findMsgById( idx ) | |
case None => None | |
} | |
val path = createPath(subFile, msg) | |
} | |
//New | |
def getPortalMsgAttachment( secureFileIdx:Long )(implicit connection:Connection):Option[SecureFile] = { | |
for { | |
secFile <- findById( secureFileIdx ) | |
idx <- secFile.portalMsgIdx | |
msg <- PortalMsgThread.findMsgById(idx) | |
diskFile <- getDiskFile(secFile,msg) | |
} yield secFile.copy(file=Some(diskFile)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment