-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic catalog service argument resolver (#103)
* dynamic catalog service argument resolver * catalog name query param constant * cleanup and afford trailing slash in base url * make catalog access params required * correct javadocs * cleanup and required config fields * update logs to use logger templating
- Loading branch information
Showing
31 changed files
with
780 additions
and
761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
service/src/main/java/edu/tamu/catalog/annotation/DefaultCatalog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package edu.tamu.catalog.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface DefaultCatalog { | ||
String value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
service/src/main/java/edu/tamu/catalog/config/CatalogServiceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package edu.tamu.catalog.config; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.core.io.support.ResourcePatternUtils; | ||
|
||
import edu.tamu.catalog.properties.CatalogServiceProperties; | ||
import edu.tamu.catalog.properties.FolioProperties; | ||
import edu.tamu.catalog.properties.VoyagerProperties; | ||
import edu.tamu.catalog.service.CatalogService; | ||
import edu.tamu.catalog.service.FolioCatalogService; | ||
import edu.tamu.catalog.service.VoyagerCatalogService; | ||
|
||
@Configuration | ||
public class CatalogServiceConfig { | ||
|
||
private static final String TYPE_FIELD = "type"; | ||
|
||
@Autowired | ||
private ConfigurableListableBeanFactory beanFactory; | ||
|
||
@Autowired | ||
private ResourceLoader resourceLoader; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Bean | ||
public List<CatalogService> createCatalogServices() throws IOException { | ||
List<CatalogService> catalogServices = new ArrayList<>(); | ||
for (Resource resource : loadResources("classpath:/catalogs/*.json")) { | ||
JsonNode propertiesNode = objectMapper.readTree(resource.getInputStream()); | ||
JsonNode typeNode = propertiesNode.get(TYPE_FIELD); | ||
if (typeNode.isValueNode()) { | ||
CatalogServiceFactory configServiceFactory = CatalogServiceFactory.valueOf(typeNode.asText().toUpperCase()); | ||
CatalogServiceProperties properties = (CatalogServiceProperties) objectMapper.treeToValue(propertiesNode, configServiceFactory.getPropertiesType()); | ||
CatalogService catalogService = configServiceFactory.build(properties); | ||
beanFactory.initializeBean(catalogService, catalogService.getName()); | ||
beanFactory.autowireBean(catalogService); | ||
beanFactory.registerSingleton(catalogService.getName(), catalogService); | ||
catalogServices.add(catalogService); | ||
} | ||
} | ||
|
||
return catalogServices; | ||
} | ||
|
||
private List<Resource> loadResources(String pattern) throws IOException { | ||
return Arrays.asList(ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources(pattern)); | ||
} | ||
|
||
private interface CatalogServiceType { | ||
public CatalogService build(CatalogServiceProperties properties); | ||
|
||
public Class<?> getPropertiesType(); | ||
} | ||
|
||
private enum CatalogServiceFactory implements CatalogServiceType { | ||
|
||
VOYAGER { | ||
@Override | ||
public CatalogService build(CatalogServiceProperties properties) { | ||
return new VoyagerCatalogService(properties); | ||
} | ||
|
||
@Override | ||
public Class<?> getPropertiesType() { | ||
return VoyagerProperties.class; | ||
} | ||
}, | ||
|
||
FOLIO { | ||
@Override | ||
public CatalogService build(CatalogServiceProperties properties) { | ||
return new FolioCatalogService(properties); | ||
} | ||
|
||
@Override | ||
public Class<?> getPropertiesType() { | ||
return FolioProperties.class; | ||
} | ||
}; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
service/src/main/java/edu/tamu/catalog/properties/AbstractCatalogServiceProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package edu.tamu.catalog.properties; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public abstract class AbstractCatalogServiceProperties implements CatalogServiceProperties { | ||
|
||
private String type; | ||
|
||
private String name; | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
service/src/main/java/edu/tamu/catalog/properties/CatalogServiceProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package edu.tamu.catalog.properties; | ||
|
||
public interface CatalogServiceProperties { | ||
|
||
public String getType(); | ||
|
||
public String getName(); | ||
|
||
} |
Oops, something went wrong.