Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/src/main/kotlin/edu/wgu/osmt/api/model/ApiSkill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ApiSkill(private val rsd: RichSkillDescriptor, private val cs: Set<Collect
get() = appConfig.defaultCreatorUri

@get:JsonProperty
val author: String?
get() = rsd.author?.let { it.value }
val authors: List<String>
get() = rsd.authors.mapNotNull { it.value }

@get:JsonProperty
val status: PublishStatus
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/kotlin/edu/wgu/osmt/api/model/ApiSkillUpdate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ data class ApiSkillUpdate(
@JsonProperty("collections")
val collections: ApiStringListUpdate? = null,

@JsonProperty("author")
val author: String? = null,
@JsonProperty("authors")
val authors: ApiStringListUpdate? = null,

@JsonProperty("keywords")
val keywords: ApiStringListUpdate? = null,
Expand Down
14 changes: 10 additions & 4 deletions api/src/main/kotlin/edu/wgu/osmt/csv/BatchImportRichSkill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class RichSkillRow: CsvRow {
@CsvBindByName(column = "O*NET Job Role")
var jobRoles: String? = null

@CsvBindByName(column = "Author")
var author: String? = null
@CsvBindByName(column = "Authors")
var authors: String? = null

@CsvBindByName(column = "Employer")
var employer: String? = null
Expand Down Expand Up @@ -135,6 +135,7 @@ class BatchImportRichSkill: CsvImport<RichSkillRow> {

for (row in rows) transaction {
var category: KeywordDao? = null
var authors: List<KeywordDao>? = null
var keywords: List<KeywordDao>? = null
var standards: List<KeywordDao>? = null
var certifications: List<KeywordDao>? = null
Expand All @@ -159,12 +160,18 @@ class BatchImportRichSkill: CsvImport<RichSkillRow> {
blsDetailed = parseJobCodes(row.blsDetaileds, JobCodeBreakout::detailedCode)
occupations = parseJobCodes(row.jobRoles, JobCodeBreakout::jobRoleCode)
collections = parseCollections(row.collections)
authors = parseKeywords(KeywordTypeEnum.Author, row.authors)

// If no Authors set to default Author
if (authors.isNullOrEmpty()) {
authors = listOf(keywordRepository.getDefaultAuthor())
}

if (row.alignmentTitle != null || row.alignmentUri != null) {
alignments = listOf( keywordRepository.findOrCreate(KeywordTypeEnum.Alignment, value = row.alignmentTitle, uri = row.alignmentUri) ).filterNotNull()
}

val allKeyWords = concatenate(keywords, standards, certifications, employers, alignments)
val allKeyWords = concatenate(keywords, authors, standards, certifications, employers, alignments)
val allJobcodes = concatenate(blsMajor,blsMinor,blsBroad,blsDetailed,occupations)

if (row.skillName != null && row.skillStatement != null) {
Expand All @@ -175,7 +182,6 @@ class BatchImportRichSkill: CsvImport<RichSkillRow> {
keywords = allKeyWords?.let { ListFieldUpdate(add = it) },
collections = collections?.let {ListFieldUpdate(add = it)},
jobCodes = allJobcodes?.let { ListFieldUpdate(add = it) },
author = NullableFieldUpdate(keywordRepository.getDefaultAuthor())
), user)
log.info("created skill '${row.skillName!!}'")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RichSkillCsvExport(
val columns = arrayOf(
CsvColumn<RichSkillAndCollections>("Canonical URL") { it.rs.canonicalUrl(appConfig.baseUrl) },
CsvColumn("RSD Name") { it.rs.name },
CsvColumn("Author") { it.rs.author?.value ?: "" },
CsvColumn("Authors") { it.rs.authors.map { author -> author.value ?: "" }.joinToString(listDelimiter) },
CsvColumn("Skill Statement") { it.rs.statement },
CsvColumn("Category") { it.rs.category?.value ?: "" },
CsvColumn("Keywords") { it.rs.searchingKeywords.map { keyword -> keyword.value ?: "" }.joinToString(listDelimiter) },
Expand Down
23 changes: 6 additions & 17 deletions api/src/main/kotlin/edu/wgu/osmt/richskill/RichSkillDescriptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ data class RichSkillDescriptor(
val jobCodes: List<JobCode> = listOf(),
val keywords: List<Keyword> = listOf(),
val category: Keyword? = null,
val author: Keyword? = null,
override val archiveDate: LocalDateTime? = null,
override val publishDate: LocalDateTime? = null,
val collections: List<Collection> = listOf()
) : DatabaseData, HasUpdateDate, PublishStatusDetails {

// Keyword collections
val authors: List<Keyword>
get() = this.keywords.filter { it.type == KeywordTypeEnum.Author }

val certifications: List<Keyword>
get() = this.keywords.filter { it.type == KeywordTypeEnum.Certification }

Expand Down Expand Up @@ -77,7 +79,7 @@ fun RichSkillDescriptor.diff(old: RichSkillDescriptor?): List<Change> {
Comparison(RichSkillDescriptor::name.name, RichSkillDescriptorComparisons::compareName, old, new),
Comparison(RichSkillDescriptor::statement.name, RichSkillDescriptorComparisons::compareStatement, old, new),
Comparison(RichSkillDescriptor::category.name, RichSkillDescriptorComparisons::compareCategory, old, new),
Comparison(RichSkillDescriptor::author.name, RichSkillDescriptorComparisons::compareAuthor, old, new),
Comparison(RichSkillDescriptor::authors.name, RichSkillDescriptorComparisons::compareAuthors, old, new),
Comparison(
RichSkillDescriptor::publishStatus.name,
RichSkillDescriptorComparisons::comparePublishStatus,
Expand Down Expand Up @@ -110,7 +112,6 @@ data class RsdUpdateObject(
override val id: Long? = null,
val name: String? = null,
val statement: String? = null,
val author: NullableFieldUpdate<KeywordDao>? = null,
val category: NullableFieldUpdate<KeywordDao>? = null,
val keywords: ListFieldUpdate<KeywordDao>? = null,
val jobCodes: ListFieldUpdate<JobCodeDao>? = null,
Expand All @@ -125,11 +126,6 @@ data class RsdUpdateObject(
validate(KeywordDao::type).isEqualTo(KeywordTypeEnum.Category)
}
}
validate(RsdUpdateObject::author).validate {
validate(NullableFieldUpdate<KeywordDao>::t).validate {
validate(KeywordDao::type).isEqualTo(KeywordTypeEnum.Author)
}
}
}
}

Expand All @@ -146,13 +142,6 @@ data class RsdUpdateObject(
dao.category = null
}
}
author?.let {
if (it.t != null) {
dao.author = it.t
} else {
dao.author = null
}
}
applyKeywords()
applyJobCodes()
applyCollections()
Expand Down Expand Up @@ -219,8 +208,8 @@ object RichSkillDescriptorComparisons {
return r.category?.value
}

fun compareAuthor(r: RichSkillDescriptor): String? {
return r.author?.value
fun compareAuthors(receiver: RichSkillDescriptor): String? {
return keywordsCompare(receiver, RichSkillDescriptor::authors)
}

fun comparePublishStatus(r: RichSkillDescriptor): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class RichSkillDescriptorDao(id: EntityID<Long>) : LongEntity(id), OutputsModel<
var uuid: String by RichSkillDescriptorTable.uuid
var name: String by RichSkillDescriptorTable.name
var statement: String by RichSkillDescriptorTable.statement
var author by KeywordDao optionalReferencedOn RichSkillDescriptorTable.author

var jobCodes by JobCodeDao via RichSkillJobCodes

Expand All @@ -45,7 +44,6 @@ class RichSkillDescriptorDao(id: EntityID<Long>) : LongEntity(id), OutputsModel<
jobCodes = jobCodes.map { it.toModel() }.sortedBy { it.code },
keywords = keywords.map { it.toModel() }.sortedBy { it.id!! },
category = category?.toModel(),
author = author?.toModel(),
archiveDate = archiveDate,
publishDate = publishDate,
collections = collections.map { it.toModel() }.toList().sortedBy { it.name }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ object RichSkillDescriptorTable : LongIdTable("RichSkillDescriptor"), TableWithU
onDelete = ReferenceOption.RESTRICT,
onUpdate = ReferenceOption.CASCADE
).nullable()
val author = reference(
"author_id",
KeywordTable,
onDelete = ReferenceOption.RESTRICT,
onUpdate = ReferenceOption.CASCADE
).nullable()
}

// many-to-many table for RichSkillDescriptor and JobCode relationship
Expand Down
7 changes: 3 additions & 4 deletions api/src/main/kotlin/edu/wgu/osmt/richskill/RichSkillDoc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ data class RichSkillDoc(
@get:JsonProperty
val category: String? = null,

@Nullable
@MultiField(
mainField = Field(type = Text, analyzer = "english_stemmer"),
otherFields = [
Expand All @@ -85,8 +84,8 @@ data class RichSkillDoc(
InnerField(suffix = "keyword", type = Keyword)
]
)
@get:JsonProperty("author")
val author: String? = null,
@get:JsonProperty("authors")
val authors: List<String> = listOf(),

@Field(type = Keyword)
@get:JsonProperty("status")
Expand Down Expand Up @@ -172,7 +171,7 @@ data class RichSkillDoc(
name = dao.name,
statement = dao.statement,
category = dao.category?.value,
author = dao.author?.value,
authors = dao.keywords.filter { it.type == KeywordTypeEnum.Author }.mapNotNull { it.value },
publishStatus = dao.publishStatus(),
searchingKeywords = dao.keywords.filter { it.type == KeywordTypeEnum.Keyword }.mapNotNull { it.value },
jobCodes = dao.jobCodes.map { it.toModel() },
Expand Down
10 changes: 5 additions & 5 deletions api/src/main/kotlin/edu/wgu/osmt/richskill/RichSkillEsRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ class CustomRichSkillQueriesImpl @Autowired constructor(override val elasticSear
}
author.nullIfEmpty()?.let {
if (it.contains("\"")) {
bq.must(simpleQueryStringQuery(it).field("${RichSkillDoc::author.name}.raw").defaultOperator(Operator.AND))
bq.must(simpleQueryStringQuery(it).field("${RichSkillDoc::authors.name}.raw").defaultOperator(Operator.AND))
Comment thread
jchavez137 marked this conversation as resolved.
} else {
bq.must(matchBoolPrefixQuery(RichSkillDoc::author.name, it))
bq.must(matchBoolPrefixQuery(RichSkillDoc::authors.name, it))
}
}
skillStatement.nullIfEmpty()?.let {
Expand Down Expand Up @@ -231,7 +231,7 @@ class CustomRichSkillQueriesImpl @Autowired constructor(override val elasticSear
}
}
authors?. let {
bq.must(buildNestedQueries(RichSkillDoc::author.name, it))
bq.must(buildNestedQueries(RichSkillDoc::authors.name, it))
Comment thread
jchavez137 marked this conversation as resolved.
}
occupations?.let {
it.mapNotNull { value ->
Expand Down Expand Up @@ -264,7 +264,7 @@ class CustomRichSkillQueriesImpl @Autowired constructor(override val elasticSear
.defaultOperator(Operator.AND),
simpleQueryStringQuery(query).field("${RichSkillDoc::employers.name}.raw").defaultOperator(Operator.AND),
simpleQueryStringQuery(query).field("${RichSkillDoc::alignments.name}.raw").defaultOperator(Operator.AND),
simpleQueryStringQuery(query).field("${RichSkillDoc::author.name}.raw").defaultOperator(Operator.AND)
simpleQueryStringQuery(query).field("${RichSkillDoc::authors.name}.raw").defaultOperator(Operator.AND)
)

val queries = listOf(
Expand All @@ -276,7 +276,7 @@ class CustomRichSkillQueriesImpl @Autowired constructor(override val elasticSear
matchPhrasePrefixQuery(RichSkillDoc::certifications.name, query),
matchPhrasePrefixQuery(RichSkillDoc::employers.name, query),
matchPhrasePrefixQuery(RichSkillDoc::alignments.name, query),
matchPhrasePrefixQuery(RichSkillDoc::author.name, query)
matchPhrasePrefixQuery(RichSkillDoc::authors.name, query)
)

if (isComplex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ class RichSkillRepositoryImpl @Autowired constructor(
this.updateDate = LocalDateTime.now(ZoneOffset.UTC)
this.creationDate = LocalDateTime.now(ZoneOffset.UTC)
this.uuid = UUID.randomUUID().toString()
this.author = updateObject.author?.t
this.category = updateObject.category?.t
}

Expand Down Expand Up @@ -203,17 +202,14 @@ class RichSkillRepositoryImpl @Autowired constructor(
}

override fun rsdUpdateFromApi(skillUpdate: ApiSkillUpdate, user: String, email: String): RsdUpdateObject {
val authorKeyword = skillUpdate.author?.let {
keywordRepository.findOrCreate(KeywordTypeEnum.Author, value = it)
}

val categoryKeyword = skillUpdate.category?.let {
keywordRepository.findOrCreate(KeywordTypeEnum.Category, value = it)
}


val addingCollections = mutableListOf<CollectionDao>()
val removingCollections = mutableListOf<CollectionDao>()
val addingAuthors = mutableListOf<KeywordDao>()
val removingAuthors = mutableListOf<KeywordDao>()
val addingKeywords = mutableListOf<KeywordDao>()
val removingKeywords = mutableListOf<KeywordDao>()
val jobsToAdd = mutableListOf<JobCodeDao>()
Expand Down Expand Up @@ -285,6 +281,7 @@ class RichSkillRepositoryImpl @Autowired constructor(
}?.let { jobsToRemove.addAll(it.filterNotNull()) }
}

skillUpdate.authors?.let { lookupKeywords(it, KeywordTypeEnum.Author) }
skillUpdate.keywords?.let { lookupKeywords(it, KeywordTypeEnum.Keyword) }
skillUpdate.certifications?.let { lookupReferences(it, KeywordTypeEnum.Certification) }
skillUpdate.standards?.let { lookupAlignments(it, KeywordTypeEnum.Standard) }
Expand Down Expand Up @@ -314,7 +311,6 @@ class RichSkillRepositoryImpl @Autowired constructor(
name = skillUpdate.skillName,
statement = skillUpdate.skillStatement,
publishStatus = skillUpdate.publishStatus,
author = authorKeyword?.let { NullableFieldUpdate(it) },
category = if (skillUpdate.category != null || skillUpdate.category?.isBlank() == true) NullableFieldUpdate(
categoryKeyword
) else null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
USE osmt_db;

--
-- Migration of RichSkillDescriptor.author_id to RichSkillKeywords table.
--

INSERT INTO RichSkillKeywords (richskill_id, keyword_id)
SELECT id, author_id
FROM RichSkillDescriptor
WHERE RichSkillDescriptor.author_id is not null;

--
-- Removal of 'author_id' from RichSkillDescriptor table.
--

ALTER TABLE `RichSkillDescriptor`
DROP FOREIGN KEY `fk_RichSkillDescriptor_author_id_id`,
DROP COLUMN `author_id`
;
12 changes: 7 additions & 5 deletions api/src/test/kotlin/edu/wgu/osmt/TestObjectHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object TestObjectHelpers {
name = randomString(),
statement = randomString(),
category = randomString(),
author = randomString()
authors = listOf(randomString())
).copy(
searchingKeywords = randomStrings(),
standards = randomStrings(),
Expand All @@ -97,7 +97,7 @@ object TestObjectHelpers {
name: String,
statement: String,
category: String? = "default category",
author: String = authorString,
authors: List<String> = listOf(authorString),
publishStatus: PublishStatus = PublishStatus.Draft
): RichSkillDoc {
val uuid = UUID.randomUUID().toString()
Expand All @@ -108,7 +108,7 @@ object TestObjectHelpers {
name = name,
statement = statement,
category = category,
author = author,
authors = authors,
publishStatus = publishStatus,
collections = listOf(collectionDoc(elasticIdCounter, UUID.randomUUID().toString(), randomString()))
)
Expand Down Expand Up @@ -165,8 +165,10 @@ object TestObjectHelpers {
val skillStatement = statement ?: UUID.randomUUID().toString()
val categoryName = UUID.randomUUID().toString()
val categoryDescription = UUID.randomUUID().toString()
val author = UUID.randomUUID().toString()

val authors = ApiStringListUpdate(
add = (1..keywordCount).toList().map { UUID.randomUUID().toString() }
)
val keywords = ApiStringListUpdate(
add = (1..keywordCount).toList().map { UUID.randomUUID().toString() }
)
Expand Down Expand Up @@ -195,7 +197,7 @@ object TestObjectHelpers {
skillStatement = skillStatement,
publishStatus = publishStatus,
category = categoryName,
author = author,
authors = authors,
keywords = keywords,
certifications = certifications,
standards = standards,
Expand Down
1 change: 0 additions & 1 deletion api/src/test/kotlin/edu/wgu/osmt/api/model/ApiSkillTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ internal class ApiSkillTest {

// Assert
Assertions.assertThat(mockData.appConfig.defaultCreatorUri).isEqualTo(actual.creator)
Assertions.assertThat(rsd.author?.value).isEqualTo(actual.author)
Assertions.assertThat(rsd.publishStatus()).isEqualTo(actual.status)
Assertions.assertThat(rsd.creationDate).isEqualTo(actual.creationDate.toLocalDateTime())
Assertions.assertThat(rsd.updateDate).isEqualTo(actual.updateDate.toLocalDateTime())
Expand Down
Loading