-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial updates for leases based on rights category
- Loading branch information
1 parent
4853417
commit b49d578
Showing
9 changed files
with
202 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// -using config lease definitions to create leases for image based on chosen rights category- | ||
export function createCategoryLeases(leaseDefs, image) { | ||
const leaseTypes = ["allow-use", "deny-use", "allow-syndication", "deny-syndication"]; | ||
const leases = []; | ||
leaseDefs.forEach((leaseDef) => { | ||
//-establish start date: TODAY | UPLOAD | TAKEN | TXDATE- | ||
const startDteType = leaseDef.startDate ?? "NONE"; | ||
let startDate = undefined; | ||
switch (startDteType) { | ||
case ("TODAY"): | ||
startDate = new Date(); | ||
break; | ||
case ("UPLOAD"): | ||
startDate = new Date(image.data.uploadTime); | ||
break; | ||
case ("TAKEN"): | ||
if (image.data.metadata.dateTaken) { | ||
startDate = new Date(image.data.metadata.dateTaken); | ||
} | ||
break; | ||
case ("TXDATE"): | ||
if (image.data.metadata.domainMetadata && | ||
image.data.metadata.domainMetadata.programmes && | ||
image.data.metadata.domainMetadata.programmes.originalTxDate) { | ||
startDate = new Date(image.data.metadata.domainMetadata.programmes.originalTxDate); | ||
} | ||
break; | ||
default: | ||
startDate = undefined; | ||
break; | ||
} | ||
// -check we have acceptable type and startDate- | ||
if (leaseTypes.includes(leaseDef.type ?? "") && startDate) { | ||
const lease = {}; | ||
lease["access"] = leaseDef.type; | ||
lease["createdAt"] = (new Date()).toISOString(); | ||
lease["leasedBy"] = "Usage_Rights_Category"; | ||
lease["startDate"] = startDate.toISOString(); | ||
lease["notes"] = leaseDef.notes ?? ""; | ||
|
||
if (leaseDef.duration) { | ||
let endDate = startDate; | ||
endDate.setFullYear(endDate.getFullYear() + leaseDef.duration); | ||
lease["endDate"] = endDate.toISOString(); | ||
} | ||
lease["mediaId"] = image.data.id; | ||
leases.push(lease); | ||
} | ||
}); | ||
return leases; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package model | ||
|
||
import com.gu.mediaservice.model._ | ||
import play.api.ConfigLoader | ||
import play.api.libs.json._ | ||
import scala.collection.JavaConverters._ | ||
import scala.util.{Failure, Success, Try} | ||
import java.time.{LocalDate, Period} | ||
|
||
case class UsageRightsLease( | ||
category: String, | ||
`type`: String, | ||
startDate: String, | ||
duration: Option[Int], | ||
notes: Option[String] | ||
) | ||
|
||
object UsageRightsLease { | ||
|
||
def getLeasesForSpec(u: UsageRightsSpec, leases: Seq[UsageRightsLease]): Seq[UsageRightsLease] = leases.filter(_.category == u.category) | ||
|
||
implicit val writes: Writes[UsageRightsLease] = Json.writes[UsageRightsLease] | ||
|
||
implicit val configLoader: ConfigLoader[Seq[UsageRightsLease]] = { | ||
ConfigLoader(_.getConfigList).map( | ||
_.asScala.map(config => { | ||
|
||
val categoryId = if (config.hasPath("category")) { | ||
config.getString("category") | ||
} else "" | ||
|
||
val leaseType = if (config.hasPath("type")) { | ||
config.getString("type") | ||
} else "" | ||
|
||
val startDate = if (config.hasPath("startDate")) { | ||
config.getString("startDate") | ||
} else "" | ||
|
||
val duration = if (config.hasPath("duration")) { | ||
Some(config.getInt("duration")) | ||
} else None | ||
|
||
val notes = if (config.hasPath("notes")) { | ||
Some(config.getString("notes")) | ||
} else None | ||
|
||
UsageRightsLease ( | ||
category = categoryId, | ||
`type` = leaseType, | ||
startDate = startDate, | ||
duration = duration, | ||
notes = notes | ||
) | ||
|
||
})) | ||
} | ||
|
||
} |