Skip to content

Commit

Permalink
SHIBUI-1902
Browse files Browse the repository at this point in the history
Bug fixes and refactoring of class names
  • Loading branch information
chasegawa committed May 25, 2021
1 parent 8fda70e commit f8a828a
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import edu.internet2.tier.shibboleth.admin.ui.domain.CustomAttributeDefinition;
import edu.internet2.tier.shibboleth.admin.ui.domain.CustomEntityAttributeDefinition;
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor;
import edu.internet2.tier.shibboleth.admin.ui.service.CustomAttributesService;
import edu.internet2.tier.shibboleth.admin.ui.service.CustomEntityAttributesDefinitionService;

@Controller
@RequestMapping(value = "/api/custom")
public class CustomAttributesController {
@RequestMapping(value = "/api/custom/entity")
public class CustomEntityAttributesDefinitionsController {
@Autowired
private CustomAttributesService caService;
private CustomEntityAttributesDefinitionService caService;

@PostMapping("/attribute")
@Transactional
public ResponseEntity<?> create(@RequestBody CustomAttributeDefinition definition) {
public ResponseEntity<?> create(@RequestBody CustomEntityAttributeDefinition definition) {
// If already defined, we can't create a new one, nor will this call update the definition
CustomAttributeDefinition cad = caService.find(definition.getName());
CustomEntityAttributeDefinition cad = caService.find(definition.getName());

if (cad != null) {
HttpHeaders headers = new HttpHeaders();
Expand All @@ -42,14 +42,14 @@ public ResponseEntity<?> create(@RequestBody CustomAttributeDefinition definitio
String.format("The custom attribute definition with name: [%s] already exists.", definition.getName())));
}

CustomAttributeDefinition result = caService.createOrUpdateDefinition(definition);
CustomEntityAttributeDefinition result = caService.createOrUpdateDefinition(definition);
return ResponseEntity.status(HttpStatus.CREATED).body(result);
}

@PutMapping("/attribute")
@Transactional
public ResponseEntity<?> update(@RequestBody CustomAttributeDefinition definition) {
CustomAttributeDefinition cad = caService.find(definition.getName());
public ResponseEntity<?> update(@RequestBody CustomEntityAttributeDefinition definition) {
CustomEntityAttributeDefinition cad = caService.find(definition.getName());
if (cad == null) {
HttpHeaders headers = new HttpHeaders();
headers.setLocation(ServletUriComponentsBuilder.fromCurrentServletMapping().path("/api/custom/attribute").build().toUri());
Expand All @@ -59,7 +59,7 @@ public ResponseEntity<?> update(@RequestBody CustomAttributeDefinition definitio
String.format("The custom attribute definition with name: [%s] does not already exist.", definition.getName())));
}

CustomAttributeDefinition result = caService.createOrUpdateDefinition(definition);
CustomEntityAttributeDefinition result = caService.createOrUpdateDefinition(definition);
return ResponseEntity.ok(result);
}

Expand All @@ -72,7 +72,7 @@ public ResponseEntity<?> getAll() {
@GetMapping("/attribute/{name}")
@Transactional(readOnly = true)
public ResponseEntity<?> getOne(@PathVariable String name) {
CustomAttributeDefinition cad = caService.find(name);
CustomEntityAttributeDefinition cad = caService.find(name);
if (cad == null) {
HttpHeaders headers = new HttpHeaders();
headers.setLocation(
Expand All @@ -88,7 +88,7 @@ public ResponseEntity<?> getOne(@PathVariable String name) {
@DeleteMapping("/attribute/{name}")
@Transactional
public ResponseEntity<?> delete(@PathVariable String name) {
CustomAttributeDefinition cad = caService.find(name);
CustomEntityAttributeDefinition cad = caService.find(name);
if (cad == null) {
HttpHeaders headers = new HttpHeaders();
headers.setLocation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

import lombok.Data;

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

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

// @TODO: logic to ensure defaultValue matches an item from the list of values when SELECTION_LIST is the type ??
}

enum CustomAttributeType {
BOOLEAN, INTEGER, LONG, DOUBLE, DURATION, SELECTION_LIST, SPRING_BEAN_ID
STRING, BOOLEAN, INTEGER, LONG, DOUBLE, DURATION, SELECTION_LIST, SPRING_BEAN_ID
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package edu.internet2.tier.shibboleth.admin.ui.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import edu.internet2.tier.shibboleth.admin.ui.domain.CustomEntityAttributeDefinition;

/**
* Repository to manage {@link CustomEntityAttributeDefinition} instances.
*/
public interface CustomEntityAttributeDefinitionRepository extends JpaRepository<CustomEntityAttributeDefinition, String> {

List<CustomEntityAttributeDefinition> findAll();

CustomEntityAttributeDefinition findByName(String name);

@SuppressWarnings("unchecked")
CustomEntityAttributeDefinition save(CustomEntityAttributeDefinition attribute);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package edu.internet2.tier.shibboleth.admin.ui.service;

import java.util.List;

import edu.internet2.tier.shibboleth.admin.ui.domain.CustomEntityAttributeDefinition;

public interface CustomEntityAttributesDefinitionService {

CustomEntityAttributeDefinition createOrUpdateDefinition(CustomEntityAttributeDefinition definition);

void deleteDefinition(CustomEntityAttributeDefinition definition);

CustomEntityAttributeDefinition find(String name);

List<CustomEntityAttributeDefinition> getAllDefinitions();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package edu.internet2.tier.shibboleth.admin.ui.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.internet2.tier.shibboleth.admin.ui.domain.CustomEntityAttributeDefinition;
import edu.internet2.tier.shibboleth.admin.ui.repository.CustomEntityAttributeDefinitionRepository;

@Service
public class CustomEntityAttributesDefinitionServiceImpl implements CustomEntityAttributesDefinitionService {
@Autowired
private CustomEntityAttributeDefinitionRepository repository;

@Override
public CustomEntityAttributeDefinition createOrUpdateDefinition(CustomEntityAttributeDefinition definition) {
return repository.save(definition);
}

@Override
public void deleteDefinition(CustomEntityAttributeDefinition definition) {
repository.delete(definition);
}

@Override
public CustomEntityAttributeDefinition find(String name) {
return repository.findByName(name);
}

@Override
public List<CustomEntityAttributeDefinition> getAllDefinitions() {
return repository.findAll();
}

}
Loading

0 comments on commit f8a828a

Please sign in to comment.