Skip to content

Commit

Permalink
SHIBUI-522: refactoring REST controller for polymorphic filters endpo…
Browse files Browse the repository at this point in the history
…ints
  • Loading branch information
dima767 committed Jun 1, 2018
1 parent 4b05a56 commit 54e898a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@

@Entity
@EqualsAndHashCode(callSuper = true, exclude={"attributeRelease", "relyingPartyOverrides"})
@NoArgsConstructor
@Getter
@Setter
@ToString
public class EntityAttributesFilter extends MetadataFilter {

@JsonProperty("@type")
private final transient String type = "EntityAttributesFilter";
public EntityAttributesFilter() {
type = "EntityAttributes";
}

@OneToOne(cascade = CascadeType.ALL)
private EntityAttributesFilterTarget entityAttributesFilterTarget;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.domain.filters;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

Expand All @@ -19,14 +15,14 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@Getter
@Setter
@ToString
public class EntityRoleWhiteListFilter extends MetadataFilter {

@JsonProperty("@type")
private final transient String type = "EntityRoleWhiteList";
public EntityRoleWhiteListFilter() {
type = "EntityRoleWhiteList";
}

private Boolean removeRolelessEntityDescriptors = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package edu.internet2.tier.shibboleth.admin.ui.domain.filters;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeId;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import edu.internet2.tier.shibboleth.admin.ui.domain.AbstractAuditable;
import lombok.EqualsAndHashCode;
Expand All @@ -21,16 +24,20 @@
*/
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@EqualsAndHashCode(callSuper = true, exclude={"version"})
@EqualsAndHashCode(callSuper = true, exclude={"version", "type"})
@NoArgsConstructor
@Getter
@Setter
@ToString
//@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
/*@JsonSubTypes({@JsonSubTypes.Type(value=EntityRoleWhiteListFilter.class, name="EntityRoleWhiteList"),
@JsonSubTypes.Type(value=EntityAttributesFilter.class, name="EntityAttributesFilter")})*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "@type", visible = true)
@JsonSubTypes({@JsonSubTypes.Type(value=EntityRoleWhiteListFilter.class, name="EntityRoleWhiteList"),
@JsonSubTypes.Type(value=EntityAttributesFilter.class, name="EntityAttributes")})
public class MetadataFilter extends AbstractAuditable {

//@JsonTypeId
@JsonProperty("@type")
transient String type;

private String name;

@Column(unique=true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class PolymorphicFiltersJacksonHandlingTests extends Specification {
def "Correct polymorphic serialization of EntityRoleWhiteListFilter"() {
given:
def givenFilterJson = """
{
"type" : "EntityRoleWhiteList",
{
"@type" : "EntityRoleWhiteList",
"createdDate" : null,
"modifiedDate" : null,
"createdBy" : null,
"modifiedBy" : null,
"name" : "EntityRoleWhiteListFilter",
"name" : "EntityRoleWhiteList",
"resourceId" : "r1",
"filterEnabled" : false,
"version" : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class JPAFilterServiceImplTests extends Specification {

def "createRepresentationFromFilter properly creates a representation from a filter"() {
given:
def filter = testObjectGenerator.buildEntityAttributesFilter()
def filter = testObjectGenerator.buildFilter { testObjectGenerator.entityAttributesFilter() }

when:
def result = service.createRepresentationFromFilter(filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class TestObjectGenerator {

EntityRoleWhiteListFilter entityRoleWhitelistFilter() {
new EntityRoleWhiteListFilter().with {
it.name = 'EntityRoleWhiteList'
it.retainedRoles = ['role1', 'role2']
it.removeRolelessEntityDescriptors = true
it
Expand All @@ -52,6 +53,7 @@ class TestObjectGenerator {

EntityAttributesFilter entityAttributesFilter() {
new EntityAttributesFilter().with {
it.name = 'EntityAttributes'
it.setEntityAttributesFilterTarget(buildEntityAttributesFilterTarget())
it.setAttributes(buildAttributesList())
it.intoTransientRepresentation()
Expand All @@ -61,7 +63,6 @@ class TestObjectGenerator {

MetadataFilter buildFilter(Supplier<? extends MetadataFilter> filterSupplier) {
MetadataFilter filter = filterSupplier.get()
filter.setName(generator.randomString(10))
filter.setFilterEnabled(generator.randomBoolean())
filter.setResourceId(generator.randomId())
return filter
Expand Down

0 comments on commit 54e898a

Please sign in to comment.