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
34 changes: 33 additions & 1 deletion api/src/main/kotlin/edu/wgu/osmt/collection/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ data class CollectionUpdateObject(

override fun applyToDao(dao: CollectionDao): Unit{
dao.updateDate = LocalDateTime.now(ZoneOffset.UTC)
applyPublishStatus(dao)
applyStatusChange(dao)
name?.let { dao.name = it }

description?.let {
Expand All @@ -76,6 +76,38 @@ data class CollectionUpdateObject(
applySkills()
}

fun applyStatusChange(dao: CollectionDao) {
when (publishStatus) {
PublishStatus.Archived -> {
dao.archiveDate = LocalDateTime.now(ZoneOffset.UTC)
dao.status = PublishStatus.Archived
}
PublishStatus.Published -> {
dao.publishDate = LocalDateTime.now(ZoneOffset.UTC)
dao.status = PublishStatus.Published
dao.archiveDate = null
}
PublishStatus.Unarchived -> {
if (dao.publishDate != null) {
dao.status = PublishStatus.Published

} else {
dao.status = PublishStatus.Draft
}
dao.archiveDate = null
}
PublishStatus.Draft -> {
dao.status = PublishStatus.Draft
dao.archiveDate = null
dao.publishDate = null
}
PublishStatus.Workspace -> {
dao.status = PublishStatus.Workspace
}
else -> {}
}
}

fun applySkills(): CollectionUpdateObject{
skills?.let {
it.add?.forEach { skill ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class CollectionRepositoryImpl @Autowired constructor(
}

updateObject.copy(id = newCollection.id.value).applyToDao(newCollection)
if(PublishStatus.Workspace == newCollection.status) {
if(PublishStatus.Workspace == updateObject.publishStatus) {
newCollection.workspaceOwner = email
}

Expand Down
8 changes: 0 additions & 8 deletions api/src/main/kotlin/edu/wgu/osmt/db/UpdateObject.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package edu.wgu.osmt.db

import edu.wgu.osmt.collection.CollectionDao
import org.apache.commons.lang3.StringUtils
import org.jetbrains.exposed.dao.LongEntity
import java.time.LocalDateTime
import java.time.ZoneOffset
Expand Down Expand Up @@ -29,11 +27,5 @@ interface HasPublishStatus<T: MutablePublishStatusDetails> {
}
else -> {} // draft is non-op
}
if(dao is CollectionDao && publishStatus != null) {
dao.status = publishStatus as PublishStatus
if (dao.status != PublishStatus.Workspace) {
dao.workspaceOwner = StringUtils.EMPTY
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
USE osmt_db;

UPDATE Collection set status = 'published' where publishDate is not null and archiveDate is null;
UPDATE Collection set status = 'archived' where archiveDate is not null;
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@ import edu.wgu.osmt.BaseDockerizedTest
import edu.wgu.osmt.HasDatabaseReset
import edu.wgu.osmt.HasElasticsearchReset
import edu.wgu.osmt.SpringTest
import edu.wgu.osmt.api.model.ApiCollectionUpdate
import edu.wgu.osmt.config.AppConfig
import edu.wgu.osmt.db.PublishStatus
import edu.wgu.osmt.jobcode.JobCodeEsRepo
import edu.wgu.osmt.keyword.KeywordEsRepo
import edu.wgu.osmt.mockdata.MockData
import edu.wgu.osmt.richskill.RichSkillEsRepo
import io.mockk.every
import io.mockk.mockk
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.core.Authentication
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.context.SecurityContext
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority
import org.springframework.security.oauth2.jwt.Jwt
import org.springframework.test.util.ReflectionTestUtils
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDateTime

@Transactional
internal class CollectionControllerTest @Autowired constructor(
Expand All @@ -31,6 +40,8 @@ internal class CollectionControllerTest @Autowired constructor(
@Autowired
lateinit var collectionController: CollectionController

var authentication: Authentication = mockk()

private lateinit var mockData : MockData

val userString = "unittestuser"
Expand All @@ -40,8 +51,20 @@ internal class CollectionControllerTest @Autowired constructor(

@BeforeAll
fun setup() {
mockData = MockData()
ReflectionTestUtils.setField(appConfig, "roleAdmin", "ROLE_Osmt_Admin")
val securityContext: SecurityContext = mockk()

SecurityContextHolder.setContext(securityContext)

val attributes: MutableMap<String, Any> = HashMap()
attributes["email"] = userEmail

val authority: GrantedAuthority = OAuth2UserAuthority("ROLE_Osmt_Admin", attributes)
val authorities: MutableSet<GrantedAuthority> = HashSet()
authorities.add(authority)

every { securityContext.authentication }.returns(authentication)
every { authentication.authorities }.returns(authorities)
}

@Test
Expand Down Expand Up @@ -70,4 +93,26 @@ internal class CollectionControllerTest @Autowired constructor(
Assertions.assertThat(collectionRepository.findAll().toList()).hasSize(1)
Assertions.assertThat(result).isNotNull
}

@Test
fun `updateCollection() should return a collection to draft status when providing an Unarchived status and update the archived date`() {
// arrange
val jwt = Jwt.withTokenValue("foo").header("foo", "foo").claim("email", userEmail).build()
val update = ApiCollectionUpdate(
name = "newName",
description = "newDescription",
publishStatus = PublishStatus.Unarchived,
author = "newAuthor")
val collection = collectionRepository.create(name = "name", user = "user", email = "user@xmail.com", description = "description")
collection!!.status = PublishStatus.Archived
collection.archiveDate = LocalDateTime.now()

// act
val result = collectionController.updateCollection(collection.uuid, update, jwt)

// assert
Assertions.assertThat(result).isNotNull
Assertions.assertThat(result.status).isEqualTo(PublishStatus.Draft)
Assertions.assertThat(result.archiveDate).isNull()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package edu.wgu.osmt.collection

import edu.wgu.osmt.SpringTest
import edu.wgu.osmt.db.PublishStatus
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDateTime

@Transactional
internal class CollectionUpdateObjectTest @Autowired constructor(
val collectionRepository: CollectionRepository
): SpringTest(){

@Test
fun `applyStatusChange() should apply Archived status`() {
//Arrange
val collectionUpdateObject = CollectionUpdateObject(publishStatus = PublishStatus.Archived)
val dao: CollectionDao =
collectionRepository.create(name = "name", user = "user", email = "user@email.edu", description = "description")!!

//Act
collectionUpdateObject.applyStatusChange(dao)

//Assert
Assertions.assertThat(dao.status).isEqualTo(PublishStatus.Archived)
Assertions.assertThat(dao.archiveDate).isNotNull
}

@Test
fun `applyStatusChange() should apply Published status`() {
//Arrange
val collectionUpdateObject = CollectionUpdateObject(publishStatus = PublishStatus.Published)
val dao: CollectionDao =
collectionRepository.create(name = "name", user = "user", email = "user@email.edu", description = "description")!!

//Act
collectionUpdateObject.applyStatusChange(dao)

//Assert
Assertions.assertThat(dao.status).isEqualTo(PublishStatus.Published)
Assertions.assertThat(dao.publishDate).isNotNull
}

@Test
fun `applyStatusChange() should return to previous draft status if no Publish date is recorded`() {
//Arrange
val collectionUpdateObject = CollectionUpdateObject(publishStatus = PublishStatus.Unarchived)
val dao: CollectionDao =
collectionRepository.create(name = "name", user = "user", email = "user@email.edu", description = "description")!!
dao.status = PublishStatus.Archived
dao.publishDate = null
Assertions.assertThat(dao.status).isEqualTo(PublishStatus.Archived)

//Act
collectionUpdateObject.applyStatusChange(dao)

//Assert
Assertions.assertThat(dao.status).isEqualTo(PublishStatus.Draft)
}

@Test
fun `applyStatusChange() should return to previous published status if Publish date is recorded`() {
//Arrange
val collectionUpdateObject = CollectionUpdateObject(publishStatus = PublishStatus.Unarchived)
val dao: CollectionDao =
collectionRepository.create(name = "name", user = "user", email = "user@email.edu", description = "description")!!
dao.status = PublishStatus.Archived
dao.publishDate = LocalDateTime.now()
Assertions.assertThat(dao.status).isEqualTo(PublishStatus.Archived)

//Act
collectionUpdateObject.applyStatusChange(dao)

//Assert
Assertions.assertThat(dao.status).isEqualTo(PublishStatus.Published)
Assertions.assertThat(dao.publishDate).isNotNull

}

@Test
fun `applyStatusChange() should delete publish and archive date if draft status is applied and Apply draft status`() {
//Arrange
val collectionUpdateObject = CollectionUpdateObject(publishStatus = PublishStatus.Draft)
val dao: CollectionDao =
collectionRepository.create(name = "name", user = "user", email = "user@email.edu", description = "description")!!
dao.publishDate = LocalDateTime.now()
dao.archiveDate = LocalDateTime.now()

//Act
collectionUpdateObject.applyStatusChange(dao)

//Assert
Assertions.assertThat(dao.status).isEqualTo(PublishStatus.Draft)
Assertions.assertThat(dao.publishDate).isNull()
Assertions.assertThat(dao.archiveDate).isNull()
}

@Test
fun `applyStatusChange() should Apply workspace status`() {
//Arrange
val collectionUpdateObject = CollectionUpdateObject(publishStatus = PublishStatus.Workspace)
val dao: CollectionDao =
collectionRepository.create(name = "name", user = "user", email = "user@email.edu", description = "description")!!
dao.publishDate = LocalDateTime.now()
dao.archiveDate = LocalDateTime.now()

//Act
collectionUpdateObject.applyStatusChange(dao)

//Assert
Assertions.assertThat(dao.status).isEqualTo(PublishStatus.Workspace)
}

}
16 changes: 16 additions & 0 deletions ui/src/app/collection/detail/manage-collection.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,22 @@ describe("ManageCollectionComponent", () => {
expect(component.getApiSearch).not.toHaveBeenCalled()
})

it("remove skills should have api search with query", () => {
component.selectAllChecked = true
const searchQuery = "art"
component.searchForm?.get("search")?.patchValue(searchQuery)
component.removeFromCollection()
expect(component.apiSearch?.query).toEqual(searchQuery)
})

it("remove skills should have api search with query", () => {
component.selectAllChecked = true
component.removeFromCollection()
const date = new Date()
component.collection = createMockCollection(date, date, date, date, PublishStatus.Workspace)
expect(component.apiSearch?.uuids?.length).toBeGreaterThan(0)
})

it("submitSkillRemoval should be correct", () => {
// Arrange
const spyReloadCollection = spyOn(component, "reloadCollection").and.returnValue()
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/collection/detail/manage-collection.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ export class ManageCollectionComponent extends SkillsListComponent implements On

getApiSearch(skill?: ApiSkillSummary): ApiSearch | undefined {
if (this.selectAllChecked) {
return new ApiSearch({
query: this.searchQuery
})
return this.searchQuery
? new ApiSearch({query: this.searchQuery})
: new ApiSearch({uuids: this.collection?.skills.map((i: any) => i.uuid)})
} else {
return super.getApiSearch(skill)
}
Expand Down
14 changes: 12 additions & 2 deletions ui/src/app/richskill/list/skills-list.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class ConcreteComponent extends SkillsListComponent {

loadNextPage(): void {}

handleSelectAll(selectAllChecked: boolean): void {}

public setResults(results: PaginatedSkills): void {
super.setResults(results)
}
Expand Down Expand Up @@ -106,6 +104,18 @@ describe("SkillsListComponent", () => {
expect(spy).toHaveBeenCalled()
})

it( "handleSelectAll should toggle select all checkbox to true",() => {
component.handleSelectAll(true)
const selectAll = component.selectAllChecked
expect(selectAll).toBeTrue()
})

it( "handleSelectAll should toggle select all checkbox to false", () => {
component["handleSelectAll"](false)
const selectAll = component.selectAllChecked
expect(selectAll).toBeFalse()
})

it("skillCountLabel should be correct", () => {
component.setResults(createMockPaginatedSkills(0, 0))
expect(component.skillCountLabel).toEqual("0 RSDs")
Expand Down
9 changes: 6 additions & 3 deletions ui/src/app/richskill/list/skills-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class SkillsListComponent extends QuickLinksHelper {
showAddToCollection = true
showExportSelected = false

selectAllChecked = false

constructor(protected router: Router,
protected richSkillService: RichSkillService,
protected collectionService: CollectionService,
Expand All @@ -72,8 +74,9 @@ export class SkillsListComponent extends QuickLinksHelper {
matchingQuery?: string[]
title?: string
loadNextPage(): void {}
handleSelectAll(selectAllChecked: boolean): void {}

handleSelectAll(selectAllChecked: boolean): void {
this.selectAllChecked = selectAllChecked
}

// base component methods

Expand Down Expand Up @@ -313,7 +316,7 @@ export class SkillsListComponent extends QuickLinksHelper {
}

protected handleClickAddToWorkspace(): void {
const skillListUpdate = this.getSelectAllEnabled() ? new ApiSkillListUpdate(
const skillListUpdate = this.selectAllChecked ? new ApiSkillListUpdate(
{add: new ApiSearch({query: this.matchingQuery?.join("")})}
) : new ApiSkillListUpdate(
{add: new ApiSearch({uuids: this.getSelectedSkills()?.map(i => i.uuid)})}
Expand Down