Skip to content

Commit

Permalink
SHIBUI-2380
Browse files Browse the repository at this point in the history
fixing repository issues with returning the protocol for EntityDescriptorProjections
  • Loading branch information
chasegawa committed Oct 20, 2022
1 parent c99265d commit a2768fb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,61 @@
package edu.internet2.tier.shibboleth.admin.ui.repository;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptorProtocol;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

public interface EntityDescriptorProjection {
default String getId() {
return getResourceId();
public class EntityDescriptorProjection {
@Getter
String id;
String entityID;
String entityId;
@Getter
String resourceId;
@Getter
String serviceProviderName;
@Getter
String createdBy;
@Getter
LocalDateTime createdDate;
@Getter
boolean serviceEnabled;
@Getter
String idOfOwner;
EntityDescriptorProtocol protocol;

public EntityDescriptorProjection(String entityID, String resourceId, String serviceProviderName, String createdBy,
LocalDateTime createdDate, boolean serviceEnabled, String idOfOwner, String protocol) {
this.entityID = entityID;
this.entityId = entityID;
this.resourceId = resourceId;
this.id = resourceId;
this.serviceProviderName = serviceProviderName;
this.createdBy = createdBy;
this.createdDate = createdDate;
this.serviceEnabled = serviceEnabled;
this.idOfOwner = idOfOwner;
setProtocol(protocol);
}

public String getEntityID() {
return entityID;
}

public String getEntityId() {
return entityId;
}

public EntityDescriptorProtocol getProtocol() {
return protocol == null ? EntityDescriptorProtocol.SAML : protocol;
}
String getEntityID();
default String getEntityId() {
return getEntityID();

public void setProtocol(String index) {
int i = Integer.valueOf(index);
protocol = EntityDescriptorProtocol.values()[i];
}
String getResourceId();
String getServiceProviderName();
String getCreatedBy();
LocalDateTime getCreatedDate();
boolean getServiceEnabled();
String getIdOfOwner();
EntityDescriptorProtocol getProtocol();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.stream.Stream;
Expand All @@ -12,9 +13,16 @@
* Repository to manage {@link EntityDescriptor} instances.
*/
public interface EntityDescriptorRepository extends JpaRepository<EntityDescriptor, Long> {
@Query(value = "select new edu.internet2.tier.shibboleth.admin.ui.repository.EntityDescriptorProjection(e.entityID, e.resourceId, e.serviceProviderName, e.createdBy, " +
"e.createdDate, e.serviceEnabled, e.idOfOwner, case e.protocol when null then 'SAML' else e.protocol end ) " +
"from EntityDescriptor e")
List<EntityDescriptorProjection> findAllBy();

List<EntityDescriptorProjection> findAllByIdOfOwner(String ownerId);
@Query(value = "select new edu.internet2.tier.shibboleth.admin.ui.repository.EntityDescriptorProjection(e.entityID, e.resourceId, e.serviceProviderName, e.createdBy, " +
"e.createdDate, e.serviceEnabled, e.idOfOwner, case e.protocol when null then 'SAML' else e.protocol end ) " +
"from EntityDescriptor e " +
"where e.idOfOwner = :ownerId")
List<EntityDescriptorProjection> findAllByIdOfOwner(@Param("ownerId") String ownerId);

EntityDescriptor findByEntityID(String entityId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import lombok.SneakyThrows
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.io.ClassPathResource
import org.springframework.security.test.context.support.WithMockUser
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.client.RestTemplate
Expand Down Expand Up @@ -160,11 +161,13 @@ class EntityDescriptorControllerTests extends AbstractBaseDataJpaTest {
def result = mockMvc.perform(get('/api/EntityDescriptors'))

then:
result.andExpect(expectedHttpResponseStatus).andExpect(content().contentType(expectedResponseContentType))
result.andDo(MockMvcResultHandlers.print())
.andExpect(expectedHttpResponseStatus).andExpect(content().contentType(expectedResponseContentType))
.andExpect(jsonPath("\$.[0].id").value("uuid-1"))
.andExpect(jsonPath("\$.[0].entityId").value("eid1"))
.andExpect(jsonPath("\$.[0].serviceEnabled").value(true))
.andExpect(jsonPath("\$.[0].idOfOwner").value("admingroup"))
.andExpect(jsonPath("\$.[0].protocol").value("SAML"))
}

@WithMockAdmin
Expand All @@ -189,10 +192,12 @@ class EntityDescriptorControllerTests extends AbstractBaseDataJpaTest {
.andExpect(jsonPath("\$.[0].entityId").value("eid1"))
.andExpect(jsonPath("\$.[0].serviceEnabled").value(true))
.andExpect(jsonPath("\$.[0].idOfOwner").value("admingroup"))
.andExpect(jsonPath("\$.[0].protocol").value("SAML"))
.andExpect(jsonPath("\$.[1].id").value("uuid-2"))
.andExpect(jsonPath("\$.[1].entityId").value("eid2"))
.andExpect(jsonPath("\$.[1].serviceEnabled").value(false))
.andExpect(jsonPath("\$.[1].idOfOwner").value("admingroup"))
.andExpect(jsonPath("\$.[1].protocol").value("SAML"))
}

@WithMockUser(value = "someUser", roles = ["USER"])
Expand Down

0 comments on commit a2768fb

Please sign in to comment.