Skip to content

Commit

Permalink
SHIBUI-1734
Browse files Browse the repository at this point in the history
Commit to branch - incomplete task
  • Loading branch information
chasegawa committed Apr 16, 2021
1 parent 171b324 commit ed2ec50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

import lombok.Data;

@Entity(name = "custom_attribute")
@Entity(name = "custom_attribute_definition")
@Audited
@Data
public class CustomAttribute {
public class CustomAttributeDefinition {
@Id
@Column(nullable = false)
String name;
Expand All @@ -32,9 +32,9 @@ public class CustomAttribute {
String defaultValue;

@ElementCollection
@CollectionTable(name = "custom_attr_values", joinColumns = @JoinColumn(name = "name"))
@CollectionTable(name = "custom_attr_list_defs", joinColumns = @JoinColumn(name = "name"))
@Column(name = "value", nullable = false)
Set<String> customAttrValues = new HashSet<>();
Set<String> customAttrListDefinitions = new HashSet<>();

// @TODO: logic to ensure defaultValue matches an item from the list of values when SELECTION_LIST is the type ??
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import edu.internet2.tier.shibboleth.admin.ui.domain.CustomAttribute;
import edu.internet2.tier.shibboleth.admin.ui.domain.CustomAttributeDefinition;

/**
* Repository to manage {@link CustomAttribute} instances.
* Repository to manage {@link CustomAttributeDefinition} instances.
*/
public interface CustomAttributeRepository extends JpaRepository<CustomAttribute, String> {
public interface CustomAttributeRepository extends JpaRepository<CustomAttributeDefinition, String> {

List<CustomAttribute> findAll();
List<CustomAttributeDefinition> findAll();

CustomAttribute findByName(String name);
CustomAttributeDefinition findByName(String name);

@SuppressWarnings("unchecked")
CustomAttribute save(CustomAttribute attribute);
CustomAttributeDefinition save(CustomAttributeDefinition attribute);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.test.context.ContextConfiguration

import edu.internet2.tier.shibboleth.admin.ui.configuration.InternationalizationConfiguration
import edu.internet2.tier.shibboleth.admin.ui.domain.CustomAttribute
import edu.internet2.tier.shibboleth.admin.ui.domain.CustomAttributeDefinition
import spock.lang.Specification

/**
Expand All @@ -31,10 +31,10 @@ class CustomAttributeRepositoryTests extends Specification {
def "basic CRUD operations validated"() {
given:
def setItems = new HashSet<String>(["val1", "val2", "val3"])
def ca = new CustomAttribute().with {
def ca = new CustomAttributeDefinition().with {
it.name = "ca-name"
it.attributeType = "SELECTION_LIST"
it.customAttrValues = setItems
it.customAttrListDefinitions = setItems
it
}

Expand All @@ -55,7 +55,7 @@ class CustomAttributeRepositoryTests extends Specification {
// save check
def cas = repo.findAll()
cas.size() == 1
def caFromDb1 = cas.get(0).asType(CustomAttribute)
def caFromDb1 = cas.get(0).asType(CustomAttributeDefinition)
caFromDb1.equals(ca) == true

// fetch checks
Expand All @@ -76,13 +76,13 @@ class CustomAttributeRepositoryTests extends Specification {
then:
def cas2 = repo.findAll()
cas2.size() == 1
def caFromDb2 = cas2.get(0).asType(CustomAttribute)
def caFromDb2 = cas2.get(0).asType(CustomAttributeDefinition)
caFromDb2.equals(ca) == false
caFromDb2.equals(caFromDb1) == true

// delete tests
when:
def delByName = new CustomAttribute().with {
def delByName = new CustomAttributeDefinition().with {
it.name = "ca-name"
it
}
Expand All @@ -99,22 +99,22 @@ class CustomAttributeRepositoryTests extends Specification {
def setItems2 = new HashSet<String>(["val2", "val1"])
def setItems3 = new HashSet<String>(["val1", "val2", "val3"])
def setItems4 = new HashSet<String>(["val1", "val2", "val3", "val4"])
def ca2 = new CustomAttribute().with {
def ca2 = new CustomAttributeDefinition().with {
it.name = "ca-name"
it.attributeType = "SELECTION_LIST"
it.customAttrValues = setItems2
it.customAttrListDefinitions = setItems2
it
}
def ca3 = new CustomAttribute().with {
def ca3 = new CustomAttributeDefinition().with {
it.name = "ca-name"
it.attributeType = "SELECTION_LIST"
it.customAttrValues = setItems3
it.customAttrListDefinitions = setItems3
it
}
def ca4 = new CustomAttribute().with {
def ca4 = new CustomAttributeDefinition().with {
it.name = "ca-name"
it.attributeType = "SELECTION_LIST"
it.customAttrValues = setItems4
it.customAttrListDefinitions = setItems4
it
}

Expand All @@ -126,31 +126,31 @@ class CustomAttributeRepositoryTests extends Specification {
then:
def cas = repo.findAll()
cas.size() == 1
def caFromDb = cas.get(0).asType(CustomAttribute)
def caFromDb = cas.get(0).asType(CustomAttributeDefinition)
caFromDb.equals(ca3) == true

// now update the attribute list items
caFromDb.with {
it.customAttrValues = setItems4
it.customAttrListDefinitions = setItems4
it
}
repo.save(caFromDb)
entityManager.flush()
entityManager.clear()

def caFromDb4 = repo.findAll().get(0).asType(CustomAttribute)
def caFromDb4 = repo.findAll().get(0).asType(CustomAttributeDefinition)
caFromDb4.equals(ca4) == true

// now remove items
caFromDb.with {
it.customAttrValues = setItems2
it.customAttrListDefinitions = setItems2
it
}
repo.save(caFromDb)
entityManager.flush()
entityManager.clear()

def caFromDb2 = repo.findAll().get(0).asType(CustomAttribute)
def caFromDb2 = repo.findAll().get(0).asType(CustomAttributeDefinition)
caFromDb2.equals(ca2) == true
}
}

0 comments on commit ed2ec50

Please sign in to comment.