diff --git a/src/main/java/org/phoebus/channelfinder/Application.java b/src/main/java/org/phoebus/channelfinder/Application.java index ca17a6df..ac5c778f 100644 --- a/src/main/java/org/phoebus/channelfinder/Application.java +++ b/src/main/java/org/phoebus/channelfinder/Application.java @@ -21,8 +21,8 @@ import java.util.ServiceLoader; import java.util.logging.Level; import java.util.logging.Logger; -import org.phoebus.channelfinder.example.PopulateService; -import org.phoebus.channelfinder.processors.ChannelProcessor; +import org.phoebus.channelfinder.configuration.ChannelProcessor; +import org.phoebus.channelfinder.configuration.PopulateDBConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; @@ -43,7 +43,7 @@ @SpringBootApplication public class Application implements ApplicationRunner { - static final Logger logger = Logger.getLogger(Application.class.getName()); + private static final Logger logger = Logger.getLogger(Application.class.getName()); public static void main(String[] args) { // Set the java truststore used by channelfinder @@ -72,7 +72,7 @@ private static void configureTruststore() { } } - @Autowired PopulateService service; + @Autowired PopulateDBConfiguration service; public void run(ApplicationArguments args) throws Exception { if (args.containsOption("demo-data")) { diff --git a/src/main/java/org/phoebus/channelfinder/CFResourceDescriptors.java b/src/main/java/org/phoebus/channelfinder/common/CFResourceDescriptors.java similarity index 95% rename from src/main/java/org/phoebus/channelfinder/CFResourceDescriptors.java rename to src/main/java/org/phoebus/channelfinder/common/CFResourceDescriptors.java index 34037fdf..a5694efa 100644 --- a/src/main/java/org/phoebus/channelfinder/CFResourceDescriptors.java +++ b/src/main/java/org/phoebus/channelfinder/common/CFResourceDescriptors.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.common; public class CFResourceDescriptors { diff --git a/src/main/java/org/phoebus/channelfinder/epics/NTXmlUtil.java b/src/main/java/org/phoebus/channelfinder/common/NTXmlUtil.java similarity index 91% rename from src/main/java/org/phoebus/channelfinder/epics/NTXmlUtil.java rename to src/main/java/org/phoebus/channelfinder/common/NTXmlUtil.java index 60e1182d..437160cb 100644 --- a/src/main/java/org/phoebus/channelfinder/epics/NTXmlUtil.java +++ b/src/main/java/org/phoebus/channelfinder/common/NTXmlUtil.java @@ -1,7 +1,7 @@ -package org.phoebus.channelfinder.epics; +package org.phoebus.channelfinder.common; -import static org.phoebus.channelfinder.epics.ChannelFinderEpicsService.COLUMN_CHANNEL_NAME; -import static org.phoebus.channelfinder.epics.ChannelFinderEpicsService.COLUMN_OWNER; +import static org.phoebus.channelfinder.service.ChannelFinderEpicsService.COLUMN_CHANNEL_NAME; +import static org.phoebus.channelfinder.service.ChannelFinderEpicsService.COLUMN_OWNER; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/org/phoebus/channelfinder/TextUtil.java b/src/main/java/org/phoebus/channelfinder/common/TextUtil.java similarity index 99% rename from src/main/java/org/phoebus/channelfinder/TextUtil.java rename to src/main/java/org/phoebus/channelfinder/common/TextUtil.java index a73d8de1..1521ce0b 100644 --- a/src/main/java/org/phoebus/channelfinder/TextUtil.java +++ b/src/main/java/org/phoebus/channelfinder/common/TextUtil.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.common; /** * Utility class to assist in handling of text. diff --git a/src/main/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessor.java b/src/main/java/org/phoebus/channelfinder/configuration/AAChannelProcessor.java similarity index 96% rename from src/main/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessor.java rename to src/main/java/org/phoebus/channelfinder/configuration/AAChannelProcessor.java index c4de947e..b0636c0c 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessor.java +++ b/src/main/java/org/phoebus/channelfinder/configuration/AAChannelProcessor.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder.processors.aa; +package org.phoebus.channelfinder.configuration; import com.fasterxml.jackson.core.JsonProcessingException; import java.util.ArrayList; @@ -14,8 +14,11 @@ import org.apache.commons.lang3.StringUtils; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; -import org.phoebus.channelfinder.processors.ChannelProcessor; -import org.phoebus.channelfinder.processors.ChannelProcessorInfo; +import org.phoebus.channelfinder.service.external.ArchiverClient; +import org.phoebus.channelfinder.service.model.archiver.ChannelProcessorInfo; +import org.phoebus.channelfinder.service.model.archiver.aa.ArchiveAction; +import org.phoebus.channelfinder.service.model.archiver.aa.ArchivePVOptions; +import org.phoebus.channelfinder.service.model.archiver.aa.ArchiverInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessor.java b/src/main/java/org/phoebus/channelfinder/configuration/ChannelProcessor.java similarity index 72% rename from src/main/java/org/phoebus/channelfinder/processors/ChannelProcessor.java rename to src/main/java/org/phoebus/channelfinder/configuration/ChannelProcessor.java index 7f9e82db..c5519ca2 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessor.java +++ b/src/main/java/org/phoebus/channelfinder/configuration/ChannelProcessor.java @@ -1,8 +1,9 @@ -package org.phoebus.channelfinder.processors; +package org.phoebus.channelfinder.configuration; import com.fasterxml.jackson.core.JsonProcessingException; import java.util.List; import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.service.model.archiver.ChannelProcessorInfo; public interface ChannelProcessor { diff --git a/src/main/java/org/phoebus/channelfinder/ElasticConfig.java b/src/main/java/org/phoebus/channelfinder/configuration/ElasticConfig.java similarity index 98% rename from src/main/java/org/phoebus/channelfinder/ElasticConfig.java rename to src/main/java/org/phoebus/channelfinder/configuration/ElasticConfig.java index 7d0943bb..736e1186 100644 --- a/src/main/java/org/phoebus/channelfinder/ElasticConfig.java +++ b/src/main/java/org/phoebus/channelfinder/configuration/ElasticConfig.java @@ -1,5 +1,5 @@ /** */ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.configuration; /* * #%L @@ -41,6 +41,7 @@ import org.apache.http.message.BasicHeader; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; +import org.phoebus.channelfinder.common.TextUtil; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; import org.springframework.beans.factory.annotation.Value; @@ -215,7 +216,7 @@ public void contextDestroyed(ServletContextEvent sce) { * * @param client client connected to elasticsearch */ - void elasticIndexValidation(ElasticsearchClient client) { + public void elasticIndexValidation(ElasticsearchClient client) { validateIndex(client, ES_CHANNEL_INDEX, "/channel_mapping.json"); validateIndex(client, ES_TAG_INDEX, "/tag_mapping.json"); validateIndex(client, ES_PROPERTY_INDEX, "/properties_mapping.json"); diff --git a/src/main/java/org/phoebus/channelfinder/HttpConnectorConfig.java b/src/main/java/org/phoebus/channelfinder/configuration/HttpConnectorConfig.java similarity index 96% rename from src/main/java/org/phoebus/channelfinder/HttpConnectorConfig.java rename to src/main/java/org/phoebus/channelfinder/configuration/HttpConnectorConfig.java index fe44408f..f4659fbe 100644 --- a/src/main/java/org/phoebus/channelfinder/HttpConnectorConfig.java +++ b/src/main/java/org/phoebus/channelfinder/configuration/HttpConnectorConfig.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.configuration; import org.apache.catalina.connector.Connector; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/org/phoebus/channelfinder/example/PopulateService.java b/src/main/java/org/phoebus/channelfinder/configuration/PopulateDBConfiguration.java similarity index 98% rename from src/main/java/org/phoebus/channelfinder/example/PopulateService.java rename to src/main/java/org/phoebus/channelfinder/configuration/PopulateDBConfiguration.java index 676bae81..3f7421d0 100644 --- a/src/main/java/org/phoebus/channelfinder/example/PopulateService.java +++ b/src/main/java/org/phoebus/channelfinder/configuration/PopulateDBConfiguration.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder.example; +package org.phoebus.channelfinder.configuration; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.Refresh; @@ -25,7 +25,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; -import org.phoebus.channelfinder.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; @@ -56,9 +55,9 @@ * @author Kunal Shroff */ @Configuration -public class PopulateService { +public class PopulateDBConfiguration { - private static final Logger logger = Logger.getLogger(PopulateService.class.getName()); + private static final Logger logger = Logger.getLogger(PopulateDBConfiguration.class.getName()); public static final String DEVICE_POWER_SUPPLY = "power supply"; public static final String DEVICE_MAGNET = "magnet"; public static final String UNIT_TEMP = "temperature"; @@ -843,7 +842,7 @@ private Collection insertValves( "{" + "GV" + "}Opn-Sw", loc, cell, - PopulateService.ELEMENT_VACUUM, + PopulateDBConfiguration.ELEMENT_VACUUM, "valve", "position", SIGTYPE_SWITCH)); @@ -857,7 +856,7 @@ private Collection insertValves( "{" + "GV" + "}Opn-St", loc, cell, - PopulateService.ELEMENT_VACUUM, + PopulateDBConfiguration.ELEMENT_VACUUM, "valve", "position", SIGTYPE_STATUS)); @@ -883,7 +882,7 @@ private Collection insertGauges( "{" + dev + "}P-RB", loc, cell, - PopulateService.ELEMENT_VACUUM, + PopulateDBConfiguration.ELEMENT_VACUUM, "gauge", "pressure", SIGTYPE_READBACK)); @@ -897,7 +896,7 @@ private Collection insertGauges( "{" + dev + OK_ST, loc, cell, - PopulateService.ELEMENT_VACUUM, + PopulateDBConfiguration.ELEMENT_VACUUM, "gauge", "error", SIGTYPE_STATUS)); @@ -922,7 +921,7 @@ private Collection insertPumps( "{" + dev + "}I-RB", loc, cell, - PopulateService.ELEMENT_VACUUM, + PopulateDBConfiguration.ELEMENT_VACUUM, "pump", UNIT_CURRENT, SIGTYPE_READBACK)); @@ -936,7 +935,7 @@ private Collection insertPumps( "{" + dev + "}P-RB", loc, cell, - PopulateService.ELEMENT_VACUUM, + PopulateDBConfiguration.ELEMENT_VACUUM, "pump", "pressure", SIGTYPE_READBACK)); @@ -950,7 +949,7 @@ private Collection insertPumps( "{" + dev + "}On-Sw", loc, cell, - PopulateService.ELEMENT_VACUUM, + PopulateDBConfiguration.ELEMENT_VACUUM, "pump", UNIT_POWER, SIGTYPE_SWITCH)); @@ -964,7 +963,7 @@ private Collection insertPumps( "{" + dev + OK_ST, loc, cell, - PopulateService.ELEMENT_VACUUM, + PopulateDBConfiguration.ELEMENT_VACUUM, "pump", "error", SIGTYPE_STATUS)); @@ -978,7 +977,7 @@ private Collection insertPumps( "{" + dev + ON_ST, loc, cell, - PopulateService.ELEMENT_VACUUM, + PopulateDBConfiguration.ELEMENT_VACUUM, "pump", UNIT_POWER, SIGTYPE_STATUS)); diff --git a/src/main/java/org/phoebus/channelfinder/RequestLoggingFilterConfig.java b/src/main/java/org/phoebus/channelfinder/configuration/RequestLoggingFilterConfig.java similarity index 92% rename from src/main/java/org/phoebus/channelfinder/RequestLoggingFilterConfig.java rename to src/main/java/org/phoebus/channelfinder/configuration/RequestLoggingFilterConfig.java index a83bb57f..48eb264c 100644 --- a/src/main/java/org/phoebus/channelfinder/RequestLoggingFilterConfig.java +++ b/src/main/java/org/phoebus/channelfinder/configuration/RequestLoggingFilterConfig.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.configuration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/org/phoebus/channelfinder/WebSecurityConfig.java b/src/main/java/org/phoebus/channelfinder/configuration/WebSecurityConfig.java similarity index 99% rename from src/main/java/org/phoebus/channelfinder/WebSecurityConfig.java rename to src/main/java/org/phoebus/channelfinder/configuration/WebSecurityConfig.java index b9868c33..4fe197da 100644 --- a/src/main/java/org/phoebus/channelfinder/WebSecurityConfig.java +++ b/src/main/java/org/phoebus/channelfinder/configuration/WebSecurityConfig.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.configuration; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/org/phoebus/channelfinder/ChannelRepository.java b/src/main/java/org/phoebus/channelfinder/repository/ChannelRepository.java similarity index 99% rename from src/main/java/org/phoebus/channelfinder/ChannelRepository.java rename to src/main/java/org/phoebus/channelfinder/repository/ChannelRepository.java index a429667e..d2f8d903 100644 --- a/src/main/java/org/phoebus/channelfinder/ChannelRepository.java +++ b/src/main/java/org/phoebus/channelfinder/repository/ChannelRepository.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.repository; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.ElasticsearchException; @@ -49,6 +49,9 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; import javax.annotation.PreDestroy; +import org.phoebus.channelfinder.common.CFResourceDescriptors; +import org.phoebus.channelfinder.common.TextUtil; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.SearchResult; diff --git a/src/main/java/org/phoebus/channelfinder/PropertyRepository.java b/src/main/java/org/phoebus/channelfinder/repository/PropertyRepository.java similarity index 99% rename from src/main/java/org/phoebus/channelfinder/PropertyRepository.java rename to src/main/java/org/phoebus/channelfinder/repository/PropertyRepository.java index 7b2a0114..696616d7 100644 --- a/src/main/java/org/phoebus/channelfinder/PropertyRepository.java +++ b/src/main/java/org/phoebus/channelfinder/repository/PropertyRepository.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.repository; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.ElasticsearchException; @@ -31,6 +31,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.StreamSupport; +import org.phoebus.channelfinder.common.TextUtil; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Property.OnlyNameOwnerProperty; diff --git a/src/main/java/org/phoebus/channelfinder/TagRepository.java b/src/main/java/org/phoebus/channelfinder/repository/TagRepository.java similarity index 98% rename from src/main/java/org/phoebus/channelfinder/TagRepository.java rename to src/main/java/org/phoebus/channelfinder/repository/TagRepository.java index 46c0e39f..37a30497 100644 --- a/src/main/java/org/phoebus/channelfinder/TagRepository.java +++ b/src/main/java/org/phoebus/channelfinder/repository/TagRepository.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.repository; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.ElasticsearchException; @@ -32,6 +32,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.StreamSupport; +import org.phoebus.channelfinder.common.TextUtil; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Tag; import org.phoebus.channelfinder.entity.Tag.OnlyTag; diff --git a/src/main/java/org/phoebus/channelfinder/rest/api/IChannel.java b/src/main/java/org/phoebus/channelfinder/rest/api/IChannel.java new file mode 100644 index 00000000..9dad009e --- /dev/null +++ b/src/main/java/org/phoebus/channelfinder/rest/api/IChannel.java @@ -0,0 +1,291 @@ +package org.phoebus.channelfinder.rest.api; + +import static org.phoebus.channelfinder.common.CFResourceDescriptors.CHANNEL_RESOURCE_URI; +import static org.phoebus.channelfinder.common.CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import java.util.List; +import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.entity.SearchResult; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.server.ResponseStatusException; + +@RequestMapping(CHANNEL_RESOURCE_URI) +public interface IChannel { + + @Operation( + summary = "Query channels", + description = + "Query a collection of Channel instances based on tags, property values, and channel names.", + operationId = "queryChannels", + tags = {"Channel"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "List of channels", + content = + @Content(array = @ArraySchema(schema = @Schema(implementation = Channel.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to find all channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping + List query( + @Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam + MultiValueMap allRequestParams); + + @Operation( + summary = "Combined query for channels", + description = + "Query for a collection of Channel instances and get a count and the first 10k hits.", + operationId = "combinedQueryChannels", + tags = {"Channel"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The number of matches for the query, and the first 10k channels", + content = + @Content( + array = @ArraySchema(schema = @Schema(implementation = SearchResult.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request - response size exceeded", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to find all channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping("/combined") + SearchResult combinedQuery( + @Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam + MultiValueMap allRequestParams); + + @Operation( + summary = "Count channels matching query", + description = "Get the number of channels matching the given query parameters.", + operationId = "countChannels", + tags = {"Channel"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The number of channels matching the query", + content = @Content(schema = @Schema(implementation = Long.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to count the result for channel-query", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping("/count") + long queryCount( + @Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam + MultiValueMap allRequestParams); + + @Operation( + summary = "Get channel by name", + description = "Retrieve a Channel instance by its name.", + operationId = "getChannelByName", + tags = {"Channel"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Channel with the specified name", + content = @Content(schema = @Schema(implementation = Channel.class))), + @ApiResponse( + responseCode = "404", + description = "Channel not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping("/{channelName}") + Channel read(@PathVariable("channelName") String channelName); + + @Operation( + summary = "Create or replace a channel", + description = "Create or replace a channel instance identified by the payload.", + operationId = "createOrReplaceChannel", + tags = {"Channel"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The created/replaced channel", + content = @Content(schema = @Schema(implementation = Channel.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Channel, Tag, or property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create channel", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PutMapping("/{channelName}") + Channel create(@PathVariable("channelName") String channelName, @RequestBody Channel channel); + + @Operation( + summary = "Create or replace multiple channels", + description = "Create or replace multiple channel instances.", + operationId = "createOrReplaceChannels", + tags = {"Channel"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The created/replaced channels", + content = + @Content(array = @ArraySchema(schema = @Schema(implementation = Channel.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag, or property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PutMapping + Iterable create(@RequestBody Iterable channels); + + @Operation( + summary = "Update a channel", + description = + "Merge properties and tags of the channel identified by the payload into an existing channel.", + operationId = "updateChannel", + tags = {"Channel"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The updated channel", + content = @Content(schema = @Schema(implementation = Channel.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Channel, Tag, or property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to update channel", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PostMapping("/{channelName}") + Channel update(@PathVariable("channelName") String channelName, @RequestBody Channel channel); + + @Operation( + summary = "Update multiple channels", + description = + "Merge properties and tags of the channels identified by the payload into existing channels.", + operationId = "updateChannels", + tags = {"Channel"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "The updated channels", + content = @Content(schema = @Schema(implementation = Channel.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Channel not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to update channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PostMapping() + Iterable update(@RequestBody Iterable channels); + + @Operation( + summary = "Delete a channel", + description = "Delete a channel instance identified by its name.", + operationId = "deleteChannel", + tags = {"Channel"}) + @ApiResponses( + value = { + @ApiResponse(responseCode = "200", description = "Channel deleted"), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Channel not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to delete channel", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @DeleteMapping("/{channelName}") + void remove(@PathVariable("channelName") String channelName); + + /** + * Checks if 1. the channel name is not null and matches the name in the body 2. the channel owner + * is not null or empty 3. all the listed tags/props exist and prop value is not null or empty + * + * @param channel channel to be validated + */ + void validateChannelRequest(Channel channel); + + /** + * Checks if 1. the tag names are not null 2. the tag owners are not null or empty 3. all the + * channels exist + * + * @param channels list of channels to be validated + */ + void validateChannelRequest(Iterable channels); +} diff --git a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorManager.java b/src/main/java/org/phoebus/channelfinder/rest/api/IChannelProcessor.java similarity index 52% rename from src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorManager.java rename to src/main/java/org/phoebus/channelfinder/rest/api/IChannelProcessor.java index 209c9ddc..4c25dcf1 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorManager.java +++ b/src/main/java/org/phoebus/channelfinder/rest/api/IChannelProcessor.java @@ -1,7 +1,7 @@ -package org.phoebus.channelfinder.processors; +package org.phoebus.channelfinder.rest.api; -import static org.phoebus.channelfinder.CFResourceDescriptors.CHANNEL_PROCESSOR_RESOURCE_URI; -import static org.phoebus.channelfinder.CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION; +import static org.phoebus.channelfinder.common.CFResourceDescriptors.CHANNEL_PROCESSOR_RESOURCE_URI; +import static org.phoebus.channelfinder.common.CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -11,42 +11,18 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.phoebus.channelfinder.AuthorizationService; -import org.phoebus.channelfinder.ChannelScroll; import org.phoebus.channelfinder.entity.Channel; -import org.phoebus.channelfinder.entity.Scroll; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.http.HttpStatus; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.util.LinkedMultiValueMap; +import org.phoebus.channelfinder.service.model.archiver.ChannelProcessorInfo; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; -@RestController @RequestMapping(CHANNEL_PROCESSOR_RESOURCE_URI) -@EnableAutoConfiguration -public class ChannelProcessorManager { - - private static final Logger logger = Logger.getLogger(ChannelProcessorManager.class.getName()); - - @Autowired ChannelProcessorService channelProcessorService; - @Autowired AuthorizationService authorizationService; - - // TODO replace with PIT and search_after - @Autowired ChannelScroll channelScroll; - - @Value("${elasticsearch.query.size:10000}") - private int defaultMaxSize; +public interface IChannelProcessor { @Operation( summary = "Get processor count", @@ -61,9 +37,7 @@ public class ChannelProcessorManager { content = @Content(schema = @Schema(implementation = Long.class))) }) @GetMapping("/count") - public long processorCount() { - return channelProcessorService.getProcessorCount(); - } + long processorCount(); @Operation( summary = "Get processor info", @@ -82,9 +56,7 @@ public long processorCount() { schema = @Schema(implementation = ChannelProcessorInfo.class)))) }) @GetMapping("/processors") - public List processorInfo() { - return channelProcessorService.getProcessorsInfo(); - } + List processorInfo(); @Operation( summary = "Process all channels", @@ -103,25 +75,7 @@ public List processorInfo() { content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) }) @PutMapping("/process/all") - public long processAllChannels() { - logger.log(Level.INFO, "Calling processor on ALL channels in ChannelFinder"); - // Only allow authorized users to trigger this operation - if (authorizationService.isAuthorizedRole( - SecurityContextHolder.getContext().getAuthentication(), - AuthorizationService.ROLES.CF_ADMIN)) { - MultiValueMap searchParameters = new LinkedMultiValueMap(); - searchParameters.add("~name", "*"); - return processChannels(searchParameters); - } else { - logger.log( - Level.SEVERE, - "User does not have the proper authorization to perform this operation: /process/all", - new ResponseStatusException(HttpStatus.UNAUTHORIZED)); - throw new ResponseStatusException( - HttpStatus.UNAUTHORIZED, - "User does not have the proper authorization to perform this operation: /process/all"); - } - } + long processAllChannels(); @Operation( summary = "Process channels by query", @@ -136,36 +90,21 @@ public long processAllChannels() { content = @Content(schema = @Schema(implementation = Long.class))) }) @PutMapping("/process/query") - public long processChannels( + long processChannels( @Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam - MultiValueMap allRequestParams) { - long channelCount = 0; - Scroll scrollResult = channelScroll.query(allRequestParams); - channelCount += scrollResult.getChannels().size(); - processChannels(scrollResult.getChannels()); - while (scrollResult.getChannels().size() == defaultMaxSize) { - scrollResult = channelScroll.search(scrollResult.getId(), allRequestParams); - channelCount += scrollResult.getChannels().size(); - processChannels(scrollResult.getChannels()); - } - return channelCount; - } + MultiValueMap allRequestParams); @PutMapping("/process/channels") - public void processChannels(List channels) { - channelProcessorService.sendToProcessors(channels); - } + void processChannels(List channels); @Operation(summary = "Set if the processor is enabled or not") @PutMapping( value = "/processor/{processorName}/enabled", produces = {"application/json"}, consumes = {"application/json"}) - public void setProcessorEnabled( + void setProcessorEnabled( @PathVariable("processorName") String processorName, @Parameter(description = "Value of enabled to set, default value: true") @RequestParam(required = false, name = "enabled", defaultValue = "true") - Boolean enabled) { - channelProcessorService.setProcessorEnabled(processorName, enabled); - } + Boolean enabled); } diff --git a/src/main/java/org/phoebus/channelfinder/rest/api/IChannelScroll.java b/src/main/java/org/phoebus/channelfinder/rest/api/IChannelScroll.java new file mode 100644 index 00000000..875d01cd --- /dev/null +++ b/src/main/java/org/phoebus/channelfinder/rest/api/IChannelScroll.java @@ -0,0 +1,83 @@ +package org.phoebus.channelfinder.rest.api; + +import static org.phoebus.channelfinder.common.CFResourceDescriptors.SCROLL_RESOURCE_URI; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.phoebus.channelfinder.common.CFResourceDescriptors; +import org.phoebus.channelfinder.entity.Scroll; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.server.ResponseStatusException; + +@RequestMapping(SCROLL_RESOURCE_URI) +public interface IChannelScroll { + + @Operation( + summary = "Scroll query for channels", + description = "Retrieve a collection of Channel instances based on multi-parameter search.", + operationId = "scrollQueryChannels", + tags = {"ChannelScroll"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Scroll that contains a collection of channel instances", + content = @Content(schema = @Schema(implementation = Scroll.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to list channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping + Scroll query( + @Parameter(description = CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION) @RequestParam + MultiValueMap allRequestParams); + + @Operation( + summary = "Scroll query by scrollId", + description = + "Retrieve a collection of Channel instances using a scrollId and search parameters.", + operationId = "scrollQueryById", + tags = {"ChannelScroll"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Scroll List of channels", + content = @Content(schema = @Schema(implementation = Scroll.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to list channels", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping("/{scrollId}") + Scroll query( + @Parameter(description = "Scroll ID from previous query") @PathVariable("scrollId") + String scrollId, + @Parameter(description = CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION) @RequestParam + MultiValueMap searchParameters); + + /** + * Search for a list of channels based on their name, tags, and/or properties. Search parameters + * ~name - The name of the channel ~tags - A list of comma separated values + * ${propertyName}:${propertyValue} - + * + *

The query result is sorted based on the channel name ~size - The number of channels to be + * returned ~from - The starting index of the channel list + * + *

TODO combine with ChannelRepository code. + * + * @param scrollId scroll ID + * @param searchParameters - search parameters for scrolling searches + * @return search scroll + */ + Scroll search(String scrollId, MultiValueMap searchParameters); +} diff --git a/src/main/java/org/phoebus/channelfinder/rest/api/IInfo.java b/src/main/java/org/phoebus/channelfinder/rest/api/IInfo.java new file mode 100644 index 00000000..7c8acf0c --- /dev/null +++ b/src/main/java/org/phoebus/channelfinder/rest/api/IInfo.java @@ -0,0 +1,31 @@ +package org.phoebus.channelfinder.rest.api; + +import static org.phoebus.channelfinder.common.CFResourceDescriptors.CF_SERVICE_INFO; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@RequestMapping(CF_SERVICE_INFO) +public interface IInfo { + + @Operation( + summary = "Get ChannelFinder service info", + description = + "Returns information about the ChannelFinder service and its Elasticsearch backend.", + operationId = "getServiceInfo", + tags = {"Info"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "ChannelFinder info", + content = @Content(schema = @Schema(implementation = String.class))) + }) + @GetMapping + String info(); +} diff --git a/src/main/java/org/phoebus/channelfinder/rest/api/IProperty.java b/src/main/java/org/phoebus/channelfinder/rest/api/IProperty.java new file mode 100644 index 00000000..a55b188a --- /dev/null +++ b/src/main/java/org/phoebus/channelfinder/rest/api/IProperty.java @@ -0,0 +1,292 @@ +package org.phoebus.channelfinder.rest.api; + +import static org.phoebus.channelfinder.common.CFResourceDescriptors.PROPERTY_RESOURCE_URI; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.phoebus.channelfinder.entity.Property; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.server.ResponseStatusException; + +@RequestMapping(PROPERTY_RESOURCE_URI) +public interface IProperty { + + @Operation( + summary = "List all properties", + description = "Retrieve the list of all properties in the database.", + operationId = "listProperties", + tags = {"Property"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "List of properties", + content = + @Content(array = @ArraySchema(schema = @Schema(implementation = Property.class)))), + @ApiResponse( + responseCode = "500", + description = "Error while listing properties", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping + Iterable list(); + + @Operation( + summary = "Get property by name", + description = "Retrieve a property by its name. Optionally include its channels.", + operationId = "getPropertyByName", + tags = {"Property"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Fetch property by propertyName", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "404", + description = "Property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping("/{propertyName}") + Property read( + @PathVariable("propertyName") String propertyName, + @RequestParam(value = "withChannels", defaultValue = "true") boolean withChannels); + + @Operation( + summary = "Create or update a property", + description = "Create and exclusively update the property identified by the path parameter.", + operationId = "createOrUpdateProperty", + tags = {"Property"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Property created", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create property", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PutMapping("/{propertyName}") + Property create( + @PathVariable("propertyName") String propertyName, @RequestBody Property property); + + @Operation( + summary = "Create multiple properties", + description = "Create multiple properties in a single request.", + operationId = "createMultipleProperties", + tags = {"Property"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Properties created", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create properties", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PutMapping() + Iterable create(@RequestBody Iterable properties); + + @Operation( + summary = "Add property to a single channel", + description = + "Add the property identified by propertyName to the channel identified by channelName.", + operationId = "addPropertyToChannel", + tags = {"Property"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Property added to the channel", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to add property", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PutMapping("/{propertyName}/{channelName}") + Property addSingle( + @PathVariable("propertyName") String propertyName, + @PathVariable("channelName") String channelName, + @RequestBody Property property); + + @Operation( + summary = "Update a property", + description = + "Update the property identified by the path parameter, adding it to all channels in the payload.", + operationId = "updateProperty", + tags = {"Property"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Property updated", + content = @Content(schema = @Schema(implementation = Property.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to update property", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PostMapping("/{propertyName}") + Property update( + @PathVariable("propertyName") String propertyName, @RequestBody Property property); + + @Operation( + summary = "Update multiple properties", + description = "Update multiple properties and all appropriate channels.", + operationId = "updateMultipleProperties", + tags = {"Property"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Properties updated", + content = + @Content(array = @ArraySchema(schema = @Schema(implementation = Property.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to update properties", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PostMapping() + Iterable update(@RequestBody Iterable properties); + + @Operation( + summary = "Delete a property", + description = "Delete the property identified by the path parameter from all channels.", + operationId = "deleteProperty", + tags = {"Property"}) + @ApiResponses( + value = { + @ApiResponse(responseCode = "200", description = "Property deleted"), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to delete property", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @DeleteMapping("/{propertyName}") + void remove(@PathVariable("propertyName") String propertyName); + + @Operation( + summary = "Delete property from a channel", + description = + "Delete the property identified by propertyName from the channel identified by channelName.", + operationId = "deletePropertyFromChannel", + tags = {"Property"}) + @ApiResponses( + value = { + @ApiResponse(responseCode = "200", description = "Property deleted from the channel"), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Property does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to delete property from a channel", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @DeleteMapping("/{propertyName}/{channelName}") + void removeSingle( + @PathVariable("propertyName") String propertyName, + @PathVariable("channelName") String channelName); + + /** + * Checks if 1. the property name is not null and matches the name in the body 2. the property + * owner is not null or empty 3. all the listed channels exist and have the property with a non + * null and non empty value + * + * @param property validate property + */ + void validatePropertyRequest(Property property); + + /** + * Checks if 1. the property name is not null and matches the name in the body 2. the property + * owner is not null or empty 3. the property value is not null or empty 4. all the listed + * channels exist + * + * @param properties properties to be validated + */ + void validatePropertyRequest(Iterable properties); + + /** + * Checks if the channel exists + * + * @param channelName check channel exists + */ + void validatePropertyRequest(String channelName); +} diff --git a/src/main/java/org/phoebus/channelfinder/rest/api/ITag.java b/src/main/java/org/phoebus/channelfinder/rest/api/ITag.java new file mode 100644 index 00000000..570ccb35 --- /dev/null +++ b/src/main/java/org/phoebus/channelfinder/rest/api/ITag.java @@ -0,0 +1,313 @@ +package org.phoebus.channelfinder.rest.api; + +import static org.phoebus.channelfinder.common.CFResourceDescriptors.TAG_RESOURCE_URI; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.phoebus.channelfinder.entity.Tag; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.server.ResponseStatusException; + +@RequestMapping(TAG_RESOURCE_URI) +public interface ITag { + + @Operation( + summary = "List all tags", + description = "Retrieve the list of all tags in the database.", + operationId = "listTags", + tags = {"Tag"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "List all Tags", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Tag.class)))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to list all Tags", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping + Iterable list(); + + @Operation( + summary = "Get tag by name", + description = "Retrieve a tag by its name. Optionally include its channels.", + operationId = "getTagByName", + tags = {"Tag"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Finding Tag by tagName", + content = @Content(schema = @Schema(implementation = Tag.class))), + @ApiResponse( + responseCode = "404", + description = "Tag not found", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @GetMapping("/{tagName}") + Tag read( + @PathVariable("tagName") String tagName, + @RequestParam(value = "withChannels", defaultValue = "true") boolean withChannels); + + @Operation( + summary = "Create or update a tag", + description = "Create and exclusively update the tag identified by the path parameter.", + operationId = "createOrUpdateTag", + tags = {"Tag"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tag created and updated", + content = @Content(schema = @Schema(implementation = Tag.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create/update Tag", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PutMapping("/{tagName}") + Tag create(@PathVariable("tagName") String tagName, @RequestBody Tag tag); + + @Operation( + summary = "Create multiple tags", + description = "Create multiple tags in a single request.", + operationId = "createMultipleTags", + tags = {"Tag"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tags created", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Tag.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while trying to create Tags", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PutMapping() + Iterable create(@RequestBody Iterable tags); + + @Operation( + summary = "Add tag to a single channel", + description = "Add the tag identified by tagName to the channel identified by channelName.", + operationId = "addTagToChannel", + tags = {"Tag"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tags added to a single channel", + content = @Content(schema = @Schema(implementation = Tag.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Tag creational error", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PutMapping("/{tagName}/{channelName}") + Tag addSingle( + @PathVariable("tagName") String tagName, @PathVariable("channelName") String channelName); + + @Operation( + summary = "Update a tag", + description = + "Update the tag identified by the path parameter, adding it to all channels in the payload.", + operationId = "updateTag", + tags = {"Tag"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tag updated", + content = @Content(schema = @Schema(implementation = Tag.class))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Tag update error", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PostMapping("/{tagName}") + Tag update(@PathVariable("tagName") String tagName, @RequestBody Tag tag); + + @Operation( + summary = "Update multiple tags", + description = + "Update multiple tags and all appropriate channels. The operation will fail if any of the specified channels do not exist.", + operationId = "updateMultipleTags", + tags = {"Tag"}) + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "Tags updated", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Tag.class)))), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag-, or Channel-name does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Error while updating tags", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @PostMapping() + Iterable update(@RequestBody Iterable tags); + + @Operation( + summary = "Delete a tag", + description = "Delete the tag identified by the path parameter from all channels.", + operationId = "deleteTag", + tags = {"Tag"}) + @ApiResponses( + value = { + @ApiResponse(responseCode = "200", description = "Tag deleted"), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Tag creational error", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @DeleteMapping("/{tagName}") + void remove(@PathVariable("tagName") String tagName); + + @Operation( + summary = "Delete tag from a channel", + description = + "Delete the tag identified by tagName from the channel identified by channelName.", + operationId = "deleteTagFromChannel", + tags = {"Tag"}) + @ApiResponses( + value = { + @ApiResponse(responseCode = "200", description = "Tag deleted from the desired channel"), + @ApiResponse( + responseCode = "400", + description = "Invalid request", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "401", + description = "Unauthorized", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "404", + description = "Tag does not exist", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), + @ApiResponse( + responseCode = "500", + description = "Tag creational error", + content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) + }) + @DeleteMapping("/{tagName}/{channelName}") + void removeSingle( + @PathVariable("tagName") String tagName, @PathVariable("channelName") String channelName); + + /** + * Checks if all the tags included satisfy the following conditions + * + *

    + *
  1. the tag names are not null or empty and matches the names in the bodies + *
  2. the tag owners are not null or empty + *
  3. all the channels exist + *
+ * + * @param tags the list of tags to be validated + */ + void validateTagRequest(Iterable tags); + + /** + * Checks if tag satisfies the following conditions + * + *
    + *
  1. the tag name is not null or empty and matches the name in the body + *
  2. the tag owner is not null or empty + *
  3. all the listed channels exist + *
+ * + * @param tag the tag to be validates + */ + void validateTagRequest(Tag tag); + + /** + * Checks if channel with name "channelName" exists + * + * @param channelName check channel exists + */ + void validateTagWithChannelRequest(String channelName); +} diff --git a/src/main/java/org/phoebus/channelfinder/ChannelManager.java b/src/main/java/org/phoebus/channelfinder/rest/controller/ChannelController.java similarity index 62% rename from src/main/java/org/phoebus/channelfinder/ChannelManager.java rename to src/main/java/org/phoebus/channelfinder/rest/controller/ChannelController.java index 061d3130..1fbb4a99 100644 --- a/src/main/java/org/phoebus/channelfinder/ChannelManager.java +++ b/src/main/java/org/phoebus/channelfinder/rest/controller/ChannelController.java @@ -1,17 +1,7 @@ -package org.phoebus.channelfinder; - -import static org.phoebus.channelfinder.CFResourceDescriptors.CHANNEL_RESOURCE_URI; -import static org.phoebus.channelfinder.CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION; +package org.phoebus.channelfinder.rest.controller; import com.google.common.collect.FluentIterable; import com.google.common.collect.Lists; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.text.MessageFormat; import java.util.List; import java.util.Map; @@ -21,38 +11,35 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; import javax.servlet.ServletContext; -import org.phoebus.channelfinder.AuthorizationService.ROLES; +import org.phoebus.channelfinder.common.TextUtil; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.SearchResult; import org.phoebus.channelfinder.entity.Tag; -import org.phoebus.channelfinder.processors.ChannelProcessorService; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; +import org.phoebus.channelfinder.rest.api.IChannel; +import org.phoebus.channelfinder.service.AuthorizationService; +import org.phoebus.channelfinder.service.AuthorizationService.ROLES; +import org.phoebus.channelfinder.service.ChannelProcessorService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.http.HttpStatus; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; @CrossOrigin @RestController -@RequestMapping(CHANNEL_RESOURCE_URI) @EnableAutoConfiguration -public class ChannelManager { +public class ChannelController implements IChannel { private static final Logger channelManagerAudit = - Logger.getLogger(ChannelManager.class.getName() + ".audit"); - private static final Logger logger = Logger.getLogger(ChannelManager.class.getName()); + Logger.getLogger(ChannelController.class.getName() + ".audit"); + private static final Logger logger = Logger.getLogger(ChannelController.class.getName()); @Autowired private ServletContext servletContext; @@ -66,106 +53,23 @@ public class ChannelManager { @Autowired ChannelProcessorService channelProcessorService; - @Operation( - summary = "Query channels", - description = - "Query a collection of Channel instances based on tags, property values, and channel names.", - operationId = "queryChannels", - tags = {"Channel"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "List of channels", - content = - @Content(array = @ArraySchema(schema = @Schema(implementation = Channel.class)))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to find all channels", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping - public List query( - @Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam - MultiValueMap allRequestParams) { + @Override + public List query(MultiValueMap allRequestParams) { return channelRepository.search(allRequestParams).channels(); } - @Operation( - summary = "Combined query for channels", - description = - "Query for a collection of Channel instances and get a count and the first 10k hits.", - operationId = "combinedQueryChannels", - tags = {"Channel"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "The number of matches for the query, and the first 10k channels", - content = - @Content( - array = @ArraySchema(schema = @Schema(implementation = SearchResult.class)))), - @ApiResponse( - responseCode = "400", - description = "Invalid request - response size exceeded", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to find all channels", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping("/combined") - public SearchResult combinedQuery( - @Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam - MultiValueMap allRequestParams) { + @Override + public SearchResult combinedQuery(MultiValueMap allRequestParams) { return channelRepository.search(allRequestParams); } - @Operation( - summary = "Count channels matching query", - description = "Get the number of channels matching the given query parameters.", - operationId = "countChannels", - tags = {"Channel"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "The number of channels matching the query", - content = @Content(schema = @Schema(implementation = Long.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to count the result for channel-query", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping("/count") - public long queryCount( - @Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam - MultiValueMap allRequestParams) { + @Override + public long queryCount(MultiValueMap allRequestParams) { return channelRepository.count(allRequestParams); } - @Operation( - summary = "Get channel by name", - description = "Retrieve a Channel instance by its name.", - operationId = "getChannelByName", - tags = {"Channel"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Channel with the specified name", - content = @Content(schema = @Schema(implementation = Channel.class))), - @ApiResponse( - responseCode = "404", - description = "Channel not found", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping("/{channelName}") - public Channel read(@PathVariable("channelName") String channelName) { + @Override + public Channel read(String channelName) { channelManagerAudit.log( Level.INFO, () -> MessageFormat.format(TextUtil.FIND_CHANNEL, channelName)); @@ -178,37 +82,8 @@ public Channel read(@PathVariable("channelName") String channelName) { } } - @Operation( - summary = "Create or replace a channel", - description = "Create or replace a channel instance identified by the payload.", - operationId = "createOrReplaceChannel", - tags = {"Channel"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "The created/replaced channel", - content = @Content(schema = @Schema(implementation = Channel.class))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Channel, Tag, or property not found", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to create channel", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PutMapping("/{channelName}") - public Channel create( - @PathVariable("channelName") String channelName, @RequestBody Channel channel) { + @Override + public Channel create(String channelName, Channel channel) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_CHANNEL)) { @@ -258,37 +133,8 @@ public Channel create( } } - @Operation( - summary = "Create or replace multiple channels", - description = "Create or replace multiple channel instances.", - operationId = "createOrReplaceChannels", - tags = {"Channel"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "The created/replaced channels", - content = - @Content(array = @ArraySchema(schema = @Schema(implementation = Channel.class)))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Tag, or property not found", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to create channels", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PutMapping - public Iterable create(@RequestBody Iterable channels) { + @Override + public Iterable create(Iterable channels) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_CHANNEL)) { @@ -378,38 +224,8 @@ private void resetOwnersToExisting(Iterable channels) { } } - @Operation( - summary = "Update a channel", - description = - "Merge properties and tags of the channel identified by the payload into an existing channel.", - operationId = "updateChannel", - tags = {"Channel"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "The updated channel", - content = @Content(schema = @Schema(implementation = Channel.class))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Channel, Tag, or property not found", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to update channel", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PostMapping("/{channelName}") - public Channel update( - @PathVariable("channelName") String channelName, @RequestBody Channel channel) { + @Override + public Channel update(String channelName, Channel channel) { if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_CHANNEL)) { long start = System.currentTimeMillis(); @@ -477,37 +293,8 @@ public Channel update( } } - @Operation( - summary = "Update multiple channels", - description = - "Merge properties and tags of the channels identified by the payload into existing channels.", - operationId = "updateChannels", - tags = {"Channel"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "The updated channels", - content = @Content(schema = @Schema(implementation = Channel.class))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Channel not found", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to update channels", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PostMapping() - public Iterable update(@RequestBody Iterable channels) { + @Override + public Iterable update(Iterable channels) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_CHANNEL)) { @@ -566,29 +353,8 @@ public Iterable update(@RequestBody Iterable channels) { } } - @Operation( - summary = "Delete a channel", - description = "Delete a channel instance identified by its name.", - operationId = "deleteChannel", - tags = {"Channel"}) - @ApiResponses( - value = { - @ApiResponse(responseCode = "200", description = "Channel deleted"), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Channel not found", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to delete channel", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @DeleteMapping("/{channelName}") - public void remove(@PathVariable("channelName") String channelName) { + @Override + public void remove(String channelName) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_CHANNEL)) { @@ -625,6 +391,7 @@ public void remove(@PathVariable("channelName") String channelName) { * * @param channel channel to be validated */ + @Override public void validateChannelRequest(Channel channel) { // 1 checkAndThrow( @@ -700,6 +467,7 @@ private static void checkAndThrow( * * @param channels list of channels to be validated */ + @Override public void validateChannelRequest(Iterable channels) { List existingProperties = StreamSupport.stream(propertyRepository.findAll().spliterator(), true) diff --git a/src/main/java/org/phoebus/channelfinder/rest/controller/ChannelProcessorController.java b/src/main/java/org/phoebus/channelfinder/rest/controller/ChannelProcessorController.java new file mode 100644 index 00000000..201b2108 --- /dev/null +++ b/src/main/java/org/phoebus/channelfinder/rest/controller/ChannelProcessorController.java @@ -0,0 +1,92 @@ +package org.phoebus.channelfinder.rest.controller; + +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.entity.Scroll; +import org.phoebus.channelfinder.rest.api.IChannelProcessor; +import org.phoebus.channelfinder.rest.api.IChannelScroll; +import org.phoebus.channelfinder.service.AuthorizationService; +import org.phoebus.channelfinder.service.ChannelProcessorService; +import org.phoebus.channelfinder.service.model.archiver.ChannelProcessorInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.http.HttpStatus; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; + +@RestController +@EnableAutoConfiguration +public class ChannelProcessorController implements IChannelProcessor { + + private static final Logger logger = Logger.getLogger(ChannelProcessorController.class.getName()); + + @Autowired ChannelProcessorService channelProcessorService; + @Autowired AuthorizationService authorizationService; + + // TODO replace with PIT and search_after + @Autowired IChannelScroll channelScroll; + + @Value("${elasticsearch.query.size:10000}") + private int defaultMaxSize; + + @Override + public long processorCount() { + return channelProcessorService.getProcessorCount(); + } + + @Override + public List processorInfo() { + return channelProcessorService.getProcessorsInfo(); + } + + @Override + public long processAllChannels() { + logger.log(Level.INFO, "Calling processor on ALL channels in ChannelFinder"); + // Only allow authorized users to trigger this operation + if (authorizationService.isAuthorizedRole( + SecurityContextHolder.getContext().getAuthentication(), + AuthorizationService.ROLES.CF_ADMIN)) { + MultiValueMap searchParameters = new LinkedMultiValueMap(); + searchParameters.add("~name", "*"); + return processChannels(searchParameters); + } else { + logger.log( + Level.SEVERE, + "User does not have the proper authorization to perform this operation: /process/all", + new ResponseStatusException(HttpStatus.UNAUTHORIZED)); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, + "User does not have the proper authorization to perform this operation: /process/all"); + } + } + + @Override + public long processChannels(MultiValueMap allRequestParams) { + long channelCount = 0; + Scroll scrollResult = channelScroll.query(allRequestParams); + channelCount += scrollResult.getChannels().size(); + processChannels(scrollResult.getChannels()); + while (scrollResult.getChannels().size() == defaultMaxSize) { + scrollResult = channelScroll.search(scrollResult.getId(), allRequestParams); + channelCount += scrollResult.getChannels().size(); + processChannels(scrollResult.getChannels()); + } + return channelCount; + } + + @Override + public void processChannels(List channels) { + channelProcessorService.sendToProcessors(channels); + } + + @Override + public void setProcessorEnabled(String processorName, Boolean enabled) { + channelProcessorService.setProcessorEnabled(processorName, enabled); + } +} diff --git a/src/main/java/org/phoebus/channelfinder/ChannelScroll.java b/src/main/java/org/phoebus/channelfinder/rest/controller/ChannelScrollController.java similarity index 73% rename from src/main/java/org/phoebus/channelfinder/ChannelScroll.java rename to src/main/java/org/phoebus/channelfinder/rest/controller/ChannelScrollController.java index 5ac61755..893d17bf 100644 --- a/src/main/java/org/phoebus/channelfinder/ChannelScroll.java +++ b/src/main/java/org/phoebus/channelfinder/rest/controller/ChannelScrollController.java @@ -1,6 +1,4 @@ -package org.phoebus.channelfinder; - -import static org.phoebus.channelfinder.CFResourceDescriptors.SCROLL_RESOURCE_URI; +package org.phoebus.channelfinder.rest.controller; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.FieldSort; @@ -10,12 +8,6 @@ import co.elastic.clients.elasticsearch.core.SearchRequest; import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.core.search.Hit; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.text.MessageFormat; import java.util.Comparator; import java.util.List; @@ -24,6 +16,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; +import org.phoebus.channelfinder.common.TextUtil; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Scroll; import org.springframework.beans.factory.annotation.Autowired; @@ -32,20 +26,15 @@ import org.springframework.http.HttpStatus; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; @CrossOrigin @RestController -@RequestMapping(SCROLL_RESOURCE_URI) @EnableAutoConfiguration -public class ChannelScroll { +public class ChannelScrollController implements org.phoebus.channelfinder.rest.api.IChannelScroll { - private static final Logger logger = Logger.getLogger(ChannelScroll.class.getName()); + private static final Logger logger = Logger.getLogger(ChannelScrollController.class.getName()); @Autowired ElasticConfig esService; @@ -53,52 +42,13 @@ public class ChannelScroll { @Qualifier("indexClient") ElasticsearchClient client; - @Operation( - summary = "Scroll query for channels", - description = "Retrieve a collection of Channel instances based on multi-parameter search.", - operationId = "scrollQueryChannels", - tags = {"ChannelScroll"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Scroll that contains a collection of channel instances", - content = @Content(schema = @Schema(implementation = Scroll.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to list channels", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping - public Scroll query( - @Parameter(description = CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION) @RequestParam - MultiValueMap allRequestParams) { + @Override + public Scroll query(MultiValueMap allRequestParams) { return search(null, allRequestParams); } - @Operation( - summary = "Scroll query by scrollId", - description = - "Retrieve a collection of Channel instances using a scrollId and search parameters.", - operationId = "scrollQueryById", - tags = {"ChannelScroll"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Scroll List of channels", - content = @Content(schema = @Schema(implementation = Scroll.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to list channels", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping("/{scrollId}") - public Scroll query( - @Parameter(description = "Scroll ID from previous query") @PathVariable("scrollId") - String scrollId, - @Parameter(description = CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION) @RequestParam - MultiValueMap searchParameters) { + @Override + public Scroll query(String scrollId, MultiValueMap searchParameters) { return search(scrollId, searchParameters); } @@ -116,6 +66,7 @@ public Scroll query( * @param searchParameters - search parameters for scrolling searches * @return search scroll */ + @Override public Scroll search(String scrollId, MultiValueMap searchParameters) { BoolQuery.Builder boolQuery = new BoolQuery.Builder(); int size = esService.getES_QUERY_SIZE(); diff --git a/src/main/java/org/phoebus/channelfinder/InfoManager.java b/src/main/java/org/phoebus/channelfinder/rest/controller/InfoController.java similarity index 62% rename from src/main/java/org/phoebus/channelfinder/InfoManager.java rename to src/main/java/org/phoebus/channelfinder/rest/controller/InfoController.java index 1c4f2c99..3a0a96cb 100644 --- a/src/main/java/org/phoebus/channelfinder/InfoManager.java +++ b/src/main/java/org/phoebus/channelfinder/rest/controller/InfoController.java @@ -1,6 +1,4 @@ -package org.phoebus.channelfinder; - -import static org.phoebus.channelfinder.CFResourceDescriptors.CF_SERVICE_INFO; +package org.phoebus.channelfinder.rest.controller; import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.ElasticsearchVersionInfo; @@ -8,28 +6,25 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; import java.util.logging.Level; +import java.util.logging.Logger; +import org.phoebus.channelfinder.configuration.ElasticConfig; +import org.phoebus.channelfinder.rest.api.IInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @CrossOrigin @RestController -@RequestMapping(CF_SERVICE_INFO) @EnableAutoConfiguration -public class InfoManager { +public class InfoController implements IInfo { + + private static final Logger logger = Logger.getLogger(InfoController.class.getName()); @Value("${channelfinder.version:4.7.0}") private String version; @@ -39,20 +34,7 @@ public class InfoManager { private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); - @Operation( - summary = "Get ChannelFinder service info", - description = - "Returns information about the ChannelFinder service and its Elasticsearch backend.", - operationId = "getServiceInfo", - tags = {"Info"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "ChannelFinder info", - content = @Content(schema = @Schema(implementation = String.class))) - }) - @GetMapping + @Override public String info() { Map cfServiceInfo = new LinkedHashMap<>(); @@ -71,16 +53,14 @@ public String info() { ElasticsearchVersionInfo elasticVersion = response.version(); elasticInfo.put("version", elasticVersion.number()); } catch (IOException e) { - Application.logger.log( - Level.WARNING, "Failed to create ChannelFinder service info resource.", e); + logger.log(Level.WARNING, "Failed to create ChannelFinder service info resource.", e); elasticInfo.put("status", "Failed to connect to elastic " + e.getLocalizedMessage()); } cfServiceInfo.put("elastic", elasticInfo); try { return objectMapper.writeValueAsString(cfServiceInfo); } catch (JsonProcessingException e) { - Application.logger.log( - Level.WARNING, "Failed to create ChannelFinder service info resource.", e); + logger.log(Level.WARNING, "Failed to create ChannelFinder service info resource.", e); return "Failed to gather ChannelFinder service info"; } } diff --git a/src/main/java/org/phoebus/channelfinder/PropertyManager.java b/src/main/java/org/phoebus/channelfinder/rest/controller/PropertyController.java similarity index 66% rename from src/main/java/org/phoebus/channelfinder/PropertyManager.java rename to src/main/java/org/phoebus/channelfinder/rest/controller/PropertyController.java index a446989c..e6ce6aeb 100644 --- a/src/main/java/org/phoebus/channelfinder/PropertyManager.java +++ b/src/main/java/org/phoebus/channelfinder/rest/controller/PropertyController.java @@ -1,14 +1,6 @@ -package org.phoebus.channelfinder; - -import static org.phoebus.channelfinder.CFResourceDescriptors.PROPERTY_RESOURCE_URI; +package org.phoebus.channelfinder.rest.controller; import com.google.common.collect.Lists; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -19,34 +11,31 @@ import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; -import org.phoebus.channelfinder.AuthorizationService.ROLES; +import org.phoebus.channelfinder.common.TextUtil; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; +import org.phoebus.channelfinder.rest.api.IProperty; +import org.phoebus.channelfinder.service.AuthorizationService; +import org.phoebus.channelfinder.service.AuthorizationService.ROLES; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.http.HttpStatus; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; @CrossOrigin @RestController -@RequestMapping(PROPERTY_RESOURCE_URI) @EnableAutoConfiguration -public class PropertyManager { +public class PropertyController implements IProperty { private static final Logger propertyManagerAudit = - Logger.getLogger(PropertyManager.class.getName() + ".audit"); - private static final Logger logger = Logger.getLogger(PropertyManager.class.getName()); + Logger.getLogger(PropertyController.class.getName() + ".audit"); + private static final Logger logger = Logger.getLogger(PropertyController.class.getName()); @Autowired TagRepository tagRepository; @@ -56,48 +45,13 @@ public class PropertyManager { @Autowired AuthorizationService authorizationService; - @Operation( - summary = "List all properties", - description = "Retrieve the list of all properties in the database.", - operationId = "listProperties", - tags = {"Property"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "List of properties", - content = - @Content(array = @ArraySchema(schema = @Schema(implementation = Property.class)))), - @ApiResponse( - responseCode = "500", - description = "Error while listing properties", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping + @Override public Iterable list() { return propertyRepository.findAll(); } - @Operation( - summary = "Get property by name", - description = "Retrieve a property by its name. Optionally include its channels.", - operationId = "getPropertyByName", - tags = {"Property"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Fetch property by propertyName", - content = @Content(schema = @Schema(implementation = Property.class))), - @ApiResponse( - responseCode = "404", - description = "Property not found", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping("/{propertyName}") - public Property read( - @PathVariable("propertyName") String propertyName, - @RequestParam(value = "withChannels", defaultValue = "true") boolean withChannels) { + @Override + public Property read(String propertyName, boolean withChannels) { propertyManagerAudit.log( Level.INFO, () -> MessageFormat.format(TextUtil.FIND_PROPERTY, propertyName)); @@ -116,33 +70,8 @@ public Property read( } } - @Operation( - summary = "Create or update a property", - description = "Create and exclusively update the property identified by the path parameter.", - operationId = "createOrUpdateProperty", - tags = {"Property"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Property created", - content = @Content(schema = @Schema(implementation = Property.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Property not found", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to create property", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PutMapping("/{propertyName}") - public Property create( - @PathVariable("propertyName") String propertyName, @RequestBody Property property) { + @Override + public Property create(String propertyName, Property property) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_PROPERTY)) { @@ -192,28 +121,8 @@ public Property create( } } - @Operation( - summary = "Create multiple properties", - description = "Create multiple properties in a single request.", - operationId = "createMultipleProperties", - tags = {"Property"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Properties created", - content = @Content(schema = @Schema(implementation = Property.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to create properties", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PutMapping() - public Iterable create(@RequestBody Iterable properties) { + @Override + public Iterable create(Iterable properties) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_PROPERTY)) { @@ -267,40 +176,8 @@ public Iterable create(@RequestBody Iterable properties) { } } - @Operation( - summary = "Add property to a single channel", - description = - "Add the property identified by propertyName to the channel identified by channelName.", - operationId = "addPropertyToChannel", - tags = {"Property"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Property added to the channel", - content = @Content(schema = @Schema(implementation = Property.class))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Property-, or Channel-name does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to add property", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PutMapping("/{propertyName}/{channelName}") - public Property addSingle( - @PathVariable("propertyName") String propertyName, - @PathVariable("channelName") String channelName, - @RequestBody Property property) { + @Override + public Property addSingle(String propertyName, String channelName, Property property) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_PROPERTY)) { @@ -349,38 +226,8 @@ public Property addSingle( } } - @Operation( - summary = "Update a property", - description = - "Update the property identified by the path parameter, adding it to all channels in the payload.", - operationId = "updateProperty", - tags = {"Property"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Property updated", - content = @Content(schema = @Schema(implementation = Property.class))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Property does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to update property", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PostMapping("/{propertyName}") - public Property update( - @PathVariable("propertyName") String propertyName, @RequestBody Property property) { + @Override + public Property update(String propertyName, Property property) { // check if authorized role if (!authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_PROPERTY)) { @@ -471,37 +318,8 @@ public Property update( return updatedProperty; } - @Operation( - summary = "Update multiple properties", - description = "Update multiple properties and all appropriate channels.", - operationId = "updateMultipleProperties", - tags = {"Property"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Properties updated", - content = - @Content(array = @ArraySchema(schema = @Schema(implementation = Property.class)))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Property does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to update properties", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PostMapping() - public Iterable update(@RequestBody Iterable properties) { + @Override + public Iterable update(Iterable properties) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_PROPERTY)) { @@ -596,29 +414,8 @@ private void checkPropertyAuthorization(Optional existingProperty) { } } - @Operation( - summary = "Delete a property", - description = "Delete the property identified by the path parameter from all channels.", - operationId = "deleteProperty", - tags = {"Property"}) - @ApiResponses( - value = { - @ApiResponse(responseCode = "200", description = "Property deleted"), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Property does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to delete property", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @DeleteMapping("/{propertyName}") - public void remove(@PathVariable("propertyName") String propertyName) { + @Override + public void remove(String propertyName) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_PROPERTY)) { @@ -647,32 +444,8 @@ public void remove(@PathVariable("propertyName") String propertyName) { } } - @Operation( - summary = "Delete property from a channel", - description = - "Delete the property identified by propertyName from the channel identified by channelName.", - operationId = "deletePropertyFromChannel", - tags = {"Property"}) - @ApiResponses( - value = { - @ApiResponse(responseCode = "200", description = "Property deleted from the channel"), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Property does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to delete property from a channel", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @DeleteMapping("/{propertyName}/{channelName}") - public void removeSingle( - @PathVariable("propertyName") final String propertyName, - @PathVariable("channelName") String channelName) { + @Override + public void removeSingle(final String propertyName, String channelName) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_PROPERTY)) { @@ -718,6 +491,7 @@ public void removeSingle( * * @param property validate property */ + @Override public void validatePropertyRequest(Property property) { // 1 if (property.getName() == null || property.getName().isEmpty()) { @@ -772,6 +546,7 @@ public void validatePropertyRequest(Property property) { * * @param properties properties to be validated */ + @Override public void validatePropertyRequest(Iterable properties) { for (Property property : properties) { validatePropertyRequest(property); @@ -783,6 +558,7 @@ public void validatePropertyRequest(Iterable properties) { * * @param channelName check channel exists */ + @Override public void validatePropertyRequest(String channelName) { if (!channelRepository.existsById(channelName)) { String message = MessageFormat.format(TextUtil.CHANNEL_NAME_DOES_NOT_EXIST, channelName); diff --git a/src/main/java/org/phoebus/channelfinder/TagManager.java b/src/main/java/org/phoebus/channelfinder/rest/controller/TagController.java similarity index 64% rename from src/main/java/org/phoebus/channelfinder/TagManager.java rename to src/main/java/org/phoebus/channelfinder/rest/controller/TagController.java index f831ec12..7bc542e8 100644 --- a/src/main/java/org/phoebus/channelfinder/TagManager.java +++ b/src/main/java/org/phoebus/channelfinder/rest/controller/TagController.java @@ -1,14 +1,6 @@ -package org.phoebus.channelfinder; - -import static org.phoebus.channelfinder.CFResourceDescriptors.TAG_RESOURCE_URI; +package org.phoebus.channelfinder.rest.controller; import com.google.common.collect.Lists; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -20,34 +12,30 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import org.phoebus.channelfinder.AuthorizationService.ROLES; +import org.phoebus.channelfinder.common.TextUtil; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.TagRepository; +import org.phoebus.channelfinder.rest.api.ITag; +import org.phoebus.channelfinder.service.AuthorizationService; +import org.phoebus.channelfinder.service.AuthorizationService.ROLES; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.http.HttpStatus; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; @CrossOrigin @RestController -@RequestMapping(TAG_RESOURCE_URI) @EnableAutoConfiguration -public class TagManager { +public class TagController implements ITag { private static final Logger tagManagerAudit = - Logger.getLogger(TagManager.class.getName() + ".audit"); - private static final Logger logger = Logger.getLogger(TagManager.class.getName()); + Logger.getLogger(TagController.class.getName() + ".audit"); + private static final Logger logger = Logger.getLogger(TagController.class.getName()); @Autowired TagRepository tagRepository; @@ -55,47 +43,13 @@ public class TagManager { @Autowired AuthorizationService authorizationService; - @Operation( - summary = "List all tags", - description = "Retrieve the list of all tags in the database.", - operationId = "listTags", - tags = {"Tag"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "List all Tags", - content = @Content(array = @ArraySchema(schema = @Schema(implementation = Tag.class)))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to list all Tags", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping + @Override public Iterable list() { return tagRepository.findAll(); } - @Operation( - summary = "Get tag by name", - description = "Retrieve a tag by its name. Optionally include its channels.", - operationId = "getTagByName", - tags = {"Tag"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Finding Tag by tagName", - content = @Content(schema = @Schema(implementation = Tag.class))), - @ApiResponse( - responseCode = "404", - description = "Tag not found", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @GetMapping("/{tagName}") - public Tag read( - @PathVariable("tagName") String tagName, - @RequestParam(value = "withChannels", defaultValue = "true") boolean withChannels) { + @Override + public Tag read(String tagName, boolean withChannels) { tagManagerAudit.log(Level.INFO, () -> MessageFormat.format(TextUtil.FIND_TAG, tagName)); if (withChannels) { @@ -119,36 +73,8 @@ public Tag read( } } - @Operation( - summary = "Create or update a tag", - description = "Create and exclusively update the tag identified by the path parameter.", - operationId = "createOrUpdateTag", - tags = {"Tag"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Tag created and updated", - content = @Content(schema = @Schema(implementation = Tag.class))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Tag-, or Channel-name does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to create/update Tag", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PutMapping("/{tagName}") - public Tag create(@PathVariable("tagName") String tagName, @RequestBody Tag tag) { + @Override + public Tag create(String tagName, Tag tag) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_TAG)) { @@ -203,36 +129,8 @@ public Tag create(@PathVariable("tagName") String tagName, @RequestBody Tag tag) } } - @Operation( - summary = "Create multiple tags", - description = "Create multiple tags in a single request.", - operationId = "createMultipleTags", - tags = {"Tag"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Tags created", - content = @Content(array = @ArraySchema(schema = @Schema(implementation = Tag.class)))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Tag-, or Channel-name does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while trying to create Tags", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PutMapping() - public Iterable create(@RequestBody Iterable tags) { + @Override + public Iterable create(Iterable tags) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_TAG)) { @@ -307,37 +205,8 @@ public Iterable create(@RequestBody Iterable tags) { } } - @Operation( - summary = "Add tag to a single channel", - description = "Add the tag identified by tagName to the channel identified by channelName.", - operationId = "addTagToChannel", - tags = {"Tag"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Tags added to a single channel", - content = @Content(schema = @Schema(implementation = Tag.class))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Tag-, or Channel-name does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Tag creational error", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PutMapping("/{tagName}/{channelName}") - public Tag addSingle( - @PathVariable("tagName") String tagName, @PathVariable("channelName") String channelName) { + @Override + public Tag addSingle(String tagName, String channelName) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_TAG)) { @@ -380,37 +249,8 @@ public Tag addSingle( } } - @Operation( - summary = "Update a tag", - description = - "Update the tag identified by the path parameter, adding it to all channels in the payload.", - operationId = "updateTag", - tags = {"Tag"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Tag updated", - content = @Content(schema = @Schema(implementation = Tag.class))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Tag name does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Tag update error", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PostMapping("/{tagName}") - public Tag update(@PathVariable("tagName") String tagName, @RequestBody Tag tag) { + @Override + public Tag update(String tagName, Tag tag) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_TAG)) { @@ -485,37 +325,8 @@ public Tag update(@PathVariable("tagName") String tagName, @RequestBody Tag tag) } } - @Operation( - summary = "Update multiple tags", - description = - "Update multiple tags and all appropriate channels. The operation will fail if any of the specified channels do not exist.", - operationId = "updateMultipleTags", - tags = {"Tag"}) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Tags updated", - content = @Content(array = @ArraySchema(schema = @Schema(implementation = Tag.class)))), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Tag-, or Channel-name does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Error while updating tags", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @PostMapping() - public Iterable update(@RequestBody Iterable tags) { + @Override + public Iterable update(Iterable tags) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_TAG)) { @@ -583,33 +394,8 @@ public Iterable update(@RequestBody Iterable tags) { } } - @Operation( - summary = "Delete a tag", - description = "Delete the tag identified by the path parameter from all channels.", - operationId = "deleteTag", - tags = {"Tag"}) - @ApiResponses( - value = { - @ApiResponse(responseCode = "200", description = "Tag deleted"), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Tag does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Tag creational error", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @DeleteMapping("/{tagName}") - public void remove(@PathVariable("tagName") String tagName) { + @Override + public void remove(String tagName) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_TAG)) { @@ -637,36 +423,8 @@ public void remove(@PathVariable("tagName") String tagName) { } } - @Operation( - summary = "Delete tag from a channel", - description = - "Delete the tag identified by tagName from the channel identified by channelName.", - operationId = "deleteTagFromChannel", - tags = {"Tag"}) - @ApiResponses( - value = { - @ApiResponse(responseCode = "200", description = "Tag deleted from the desired channel"), - @ApiResponse( - responseCode = "400", - description = "Invalid request", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "401", - description = "Unauthorized", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "404", - description = "Tag does not exist", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))), - @ApiResponse( - responseCode = "500", - description = "Tag creational error", - content = @Content(schema = @Schema(implementation = ResponseStatusException.class))) - }) - @DeleteMapping("/{tagName}/{channelName}") - public void removeSingle( - @PathVariable("tagName") final String tagName, - @PathVariable("channelName") String channelName) { + @Override + public void removeSingle(final String tagName, String channelName) { // check if authorized role if (authorizationService.isAuthorizedRole( SecurityContextHolder.getContext().getAuthentication(), ROLES.CF_TAG)) { @@ -715,6 +473,7 @@ public void removeSingle( * * @param tags the list of tags to be validated */ + @Override public void validateTagRequest(Iterable tags) { for (Tag tag : tags) { validateTagRequest(tag); @@ -732,6 +491,7 @@ public void validateTagRequest(Iterable tags) { * * @param tag the tag to be validates */ + @Override public void validateTagRequest(Tag tag) { // 1 if (tag.getName() == null || tag.getName().isEmpty()) { @@ -763,6 +523,7 @@ public void validateTagRequest(Tag tag) { * * @param channelName check channel exists */ + @Override public void validateTagWithChannelRequest(String channelName) { if (!channelRepository.existsById(channelName)) { String message = MessageFormat.format(TextUtil.CHANNEL_NAME_DOES_NOT_EXIST, channelName); diff --git a/src/main/java/org/phoebus/channelfinder/AuthorizationService.java b/src/main/java/org/phoebus/channelfinder/service/AuthorizationService.java similarity index 99% rename from src/main/java/org/phoebus/channelfinder/AuthorizationService.java rename to src/main/java/org/phoebus/channelfinder/service/AuthorizationService.java index 822fd43e..af4cf8d3 100644 --- a/src/main/java/org/phoebus/channelfinder/AuthorizationService.java +++ b/src/main/java/org/phoebus/channelfinder/service/AuthorizationService.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.service; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/org/phoebus/channelfinder/epics/ChannelFinderEpicsService.java b/src/main/java/org/phoebus/channelfinder/service/ChannelFinderEpicsService.java similarity index 98% rename from src/main/java/org/phoebus/channelfinder/epics/ChannelFinderEpicsService.java rename to src/main/java/org/phoebus/channelfinder/service/ChannelFinderEpicsService.java index 96c00786..a1a3dc73 100644 --- a/src/main/java/org/phoebus/channelfinder/epics/ChannelFinderEpicsService.java +++ b/src/main/java/org/phoebus/channelfinder/service/ChannelFinderEpicsService.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder.epics; +package org.phoebus.channelfinder.service; import java.util.Arrays; import java.util.HashMap; @@ -19,8 +19,8 @@ import org.epics.pva.server.PVAServer; import org.epics.pva.server.RPCService; import org.epics.pva.server.ServerPV; -import org.phoebus.channelfinder.ChannelRepository; import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.repository.ChannelRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorService.java b/src/main/java/org/phoebus/channelfinder/service/ChannelProcessorService.java similarity index 90% rename from src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorService.java rename to src/main/java/org/phoebus/channelfinder/service/ChannelProcessorService.java index a87c954a..26b62dc4 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorService.java +++ b/src/main/java/org/phoebus/channelfinder/service/ChannelProcessorService.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder.processors; +package org.phoebus.channelfinder.service; import java.util.ArrayList; import java.util.List; @@ -8,7 +8,9 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; +import org.phoebus.channelfinder.configuration.ChannelProcessor; import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.service.model.archiver.ChannelProcessorInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.task.TaskExecutor; @@ -34,15 +36,15 @@ public ChannelProcessorService( this.chunkSize = chunkSize; } - long getProcessorCount() { + public long getProcessorCount() { return channelProcessors.size(); } - List getProcessorsInfo() { + public List getProcessorsInfo() { return channelProcessors.stream().map(ChannelProcessor::processorInfo).toList(); } - void setProcessorEnabled(String name, boolean enabled) { + public void setProcessorEnabled(String name, boolean enabled) { Optional processor = channelProcessors.stream() .filter(p -> Objects.equals(p.processorInfo().name(), name)) diff --git a/src/main/java/org/phoebus/channelfinder/MetricsService.java b/src/main/java/org/phoebus/channelfinder/service/MetricsService.java similarity index 97% rename from src/main/java/org/phoebus/channelfinder/MetricsService.java rename to src/main/java/org/phoebus/channelfinder/service/MetricsService.java index 78db0e8e..0d78df12 100644 --- a/src/main/java/org/phoebus/channelfinder/MetricsService.java +++ b/src/main/java/org/phoebus/channelfinder/service/MetricsService.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder; +package org.phoebus.channelfinder.service; import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.ImmutableTag; @@ -13,6 +13,9 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import javax.annotation.PostConstruct; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; diff --git a/src/main/java/org/phoebus/channelfinder/processors/aa/ArchiverClient.java b/src/main/java/org/phoebus/channelfinder/service/external/ArchiverClient.java similarity index 95% rename from src/main/java/org/phoebus/channelfinder/processors/aa/ArchiverClient.java rename to src/main/java/org/phoebus/channelfinder/service/external/ArchiverClient.java index ee7edd65..7f15b703 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/aa/ArchiverClient.java +++ b/src/main/java/org/phoebus/channelfinder/service/external/ArchiverClient.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder.processors.aa; +package org.phoebus.channelfinder.service.external; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -16,6 +16,8 @@ import java.util.stream.IntStream; import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; +import org.phoebus.channelfinder.service.model.archiver.aa.ArchiveAction; +import org.phoebus.channelfinder.service.model.archiver.aa.ArchivePVOptions; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; @@ -50,7 +52,7 @@ private Stream> partitionSet(Set pvSet, int pageSize) { .mapToObj(i -> list.subList(i * pageSize, Math.min(pageSize * (i + 1), list.size()))); } - List> getStatuses( + public List> getStatuses( Map archivePVS, String archiverURL, String archiverAlias) { Set pvs = archivePVS.keySet(); Boolean postSupportOverride = postSupportArchivers.contains(archiverAlias); @@ -158,7 +160,7 @@ private void submitAction(String values, String endpoint, String aaURL) { } } - long configureAA(Map> archivePVS, String aaURL) + public long configureAA(Map> archivePVS, String aaURL) throws JsonProcessingException { logger.log( Level.INFO, () -> String.format("Configure PVs %s in %s", archivePVS.toString(), aaURL)); @@ -207,7 +209,7 @@ long configureAA(Map> archivePVS, String a return count; } - List getAAPolicies(String aaURL) { + public List getAAPolicies(String aaURL) { if (StringUtils.isEmpty(aaURL)) { return List.of(); } @@ -231,7 +233,7 @@ List getAAPolicies(String aaURL) { } } - String getVersion(String archiverURL) { + public String getVersion(String archiverURL) { try { String uriString = archiverURL + ARCHIVER_VERSIONS_RESOURCE; String response = diff --git a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorInfo.java b/src/main/java/org/phoebus/channelfinder/service/model/archiver/ChannelProcessorInfo.java similarity index 68% rename from src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorInfo.java rename to src/main/java/org/phoebus/channelfinder/service/model/archiver/ChannelProcessorInfo.java index a4e77d16..8b48d851 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorInfo.java +++ b/src/main/java/org/phoebus/channelfinder/service/model/archiver/ChannelProcessorInfo.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder.processors; +package org.phoebus.channelfinder.service.model.archiver; import java.util.Map; diff --git a/src/main/java/org/phoebus/channelfinder/processors/aa/ArchiveAction.java b/src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchiveAction.java similarity index 83% rename from src/main/java/org/phoebus/channelfinder/processors/aa/ArchiveAction.java rename to src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchiveAction.java index d44545b1..40d3d4be 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/aa/ArchiveAction.java +++ b/src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchiveAction.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder.processors.aa; +package org.phoebus.channelfinder.service.model.archiver.aa; public enum ArchiveAction { ARCHIVE("/archivePV"), diff --git a/src/main/java/org/phoebus/channelfinder/processors/aa/ArchivePVOptions.java b/src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchivePVOptions.java similarity index 97% rename from src/main/java/org/phoebus/channelfinder/processors/aa/ArchivePVOptions.java rename to src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchivePVOptions.java index b483a12f..05c6e0d0 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/aa/ArchivePVOptions.java +++ b/src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchivePVOptions.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder.processors.aa; +package org.phoebus.channelfinder.service.model.archiver.aa; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/src/main/java/org/phoebus/channelfinder/processors/aa/ArchiverInfo.java b/src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchiverInfo.java similarity index 66% rename from src/main/java/org/phoebus/channelfinder/processors/aa/ArchiverInfo.java rename to src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchiverInfo.java index 31219b53..4d43bdac 100644 --- a/src/main/java/org/phoebus/channelfinder/processors/aa/ArchiverInfo.java +++ b/src/main/java/org/phoebus/channelfinder/service/model/archiver/aa/ArchiverInfo.java @@ -1,4 +1,4 @@ -package org.phoebus.channelfinder.processors.aa; +package org.phoebus.channelfinder.service.model.archiver.aa; import java.util.List; diff --git a/src/main/resources/META-INF/services/org.phoebus.channelfinder.configuration.ChannelProcessor b/src/main/resources/META-INF/services/org.phoebus.channelfinder.configuration.ChannelProcessor new file mode 100644 index 00000000..c1948c9e --- /dev/null +++ b/src/main/resources/META-INF/services/org.phoebus.channelfinder.configuration.ChannelProcessor @@ -0,0 +1 @@ +org.phoebus.channelfinder.configuration.AAChannelProcessor \ No newline at end of file diff --git a/src/main/resources/META-INF/services/org.phoebus.channelfinder.processors.ChannelProcessor b/src/main/resources/META-INF/services/org.phoebus.channelfinder.processors.ChannelProcessor deleted file mode 100644 index 1f2d383c..00000000 --- a/src/main/resources/META-INF/services/org.phoebus.channelfinder.processors.ChannelProcessor +++ /dev/null @@ -1 +0,0 @@ -org.phoebus.channelfinder.processors.aa.AAChannelProcessor \ No newline at end of file diff --git a/src/test/java/org/phoebus/channelfinder/AuthorizationIT.java b/src/test/java/org/phoebus/channelfinder/AuthorizationIT.java index d6622a09..42156912 100644 --- a/src/test/java/org/phoebus/channelfinder/AuthorizationIT.java +++ b/src/test/java/org/phoebus/channelfinder/AuthorizationIT.java @@ -2,10 +2,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.phoebus.channelfinder.AuthorizationService.ROLES; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.service.AuthorizationService; +import org.phoebus.channelfinder.service.AuthorizationService.ROLES; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.core.context.SecurityContextHolder; diff --git a/src/test/java/org/phoebus/channelfinder/ChannelManagerIT.java b/src/test/java/org/phoebus/channelfinder/ChannelControllerIT.java similarity index 97% rename from src/test/java/org/phoebus/channelfinder/ChannelManagerIT.java rename to src/test/java/org/phoebus/channelfinder/ChannelControllerIT.java index dd3fd584..2726265f 100644 --- a/src/test/java/org/phoebus/channelfinder/ChannelManagerIT.java +++ b/src/test/java/org/phoebus/channelfinder/ChannelControllerIT.java @@ -13,9 +13,15 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; +import org.phoebus.channelfinder.rest.api.IChannel; +import org.phoebus.channelfinder.rest.controller.ChannelController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; @@ -23,12 +29,12 @@ import org.springframework.web.server.ResponseStatusException; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@WebMvcTest(ChannelManager.class) +@WebMvcTest(ChannelController.class) @WithMockUser(roles = "CF-ADMINS") @TestPropertySource(value = "classpath:application_test.properties") -class ChannelManagerIT { +class ChannelControllerIT { - @Autowired ChannelManager channelManager; + @Autowired IChannel channelManager; @Autowired TagRepository tagRepository; diff --git a/src/test/java/org/phoebus/channelfinder/ChannelRepositoryIT.java b/src/test/java/org/phoebus/channelfinder/ChannelRepositoryIT.java index 909c6499..2225cbc9 100644 --- a/src/test/java/org/phoebus/channelfinder/ChannelRepositoryIT.java +++ b/src/test/java/org/phoebus/channelfinder/ChannelRepositoryIT.java @@ -15,10 +15,14 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.SearchResult; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.TestPropertySource; diff --git a/src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java b/src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java index 8a127c47..db0591b2 100644 --- a/src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java +++ b/src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java @@ -1,8 +1,8 @@ package org.phoebus.channelfinder; import static java.lang.Math.min; -import static org.phoebus.channelfinder.example.PopulateService.valBucket; -import static org.phoebus.channelfinder.example.PopulateService.valBucketSize; +import static org.phoebus.channelfinder.configuration.PopulateDBConfiguration.valBucket; +import static org.phoebus.channelfinder.configuration.PopulateDBConfiguration.valBucketSize; import java.io.IOException; import java.util.Arrays; @@ -16,8 +16,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; +import org.phoebus.channelfinder.configuration.PopulateDBConfiguration; import org.phoebus.channelfinder.entity.SearchResult; -import org.phoebus.channelfinder.example.PopulateService; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -38,7 +42,7 @@ class ChannelRepositorySearchIT { @Autowired TagRepository tagRepository; @Autowired PropertyRepository propertyRepository; @Autowired ElasticConfig esService; - @Autowired PopulateService populateService; + @Autowired PopulateDBConfiguration populateDBConfiguration; @Value("${elasticsearch.query.size:10000}") int ELASTIC_LIMIT; @@ -50,14 +54,14 @@ void setupAll() { @BeforeEach public void setup() throws InterruptedException { - populateService.cleanupDB(); - populateService.createDB(CELLS); + populateDBConfiguration.cleanupDB(); + populateDBConfiguration.createDB(CELLS); Thread.sleep(5000); } @AfterEach public void cleanup() throws InterruptedException { - populateService.cleanupDB(); + populateDBConfiguration.cleanupDB(); } /** @@ -68,7 +72,7 @@ public void cleanup() throws InterruptedException { @Test void searchTest() { List channelNames = - Arrays.asList(populateService.getChannelList().toArray(new String[0])); + Arrays.asList(populateDBConfiguration.getChannelList().toArray(new String[0])); MultiValueMap searchParameters = new LinkedMultiValueMap(); // logger.log(Level.INFO, "Search for a single unique channel " + channelNames.get(0)); diff --git a/src/test/java/org/phoebus/channelfinder/ChannelScrollIT.java b/src/test/java/org/phoebus/channelfinder/ChannelScrollControllerIT.java similarity index 89% rename from src/test/java/org/phoebus/channelfinder/ChannelScrollIT.java rename to src/test/java/org/phoebus/channelfinder/ChannelScrollControllerIT.java index 2e40fbc4..d3404f74 100644 --- a/src/test/java/org/phoebus/channelfinder/ChannelScrollIT.java +++ b/src/test/java/org/phoebus/channelfinder/ChannelScrollControllerIT.java @@ -5,9 +5,15 @@ import java.util.List; import java.util.Random; import org.junit.jupiter.api.*; +import org.phoebus.channelfinder.configuration.ElasticConfig; +import org.phoebus.channelfinder.configuration.PopulateDBConfiguration; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Scroll; -import org.phoebus.channelfinder.example.PopulateService; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; +import org.phoebus.channelfinder.rest.api.IChannelScroll; +import org.phoebus.channelfinder.rest.controller.ChannelScrollController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.TestPropertySource; @@ -15,11 +21,11 @@ import org.springframework.util.MultiValueMap; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@WebMvcTest(ChannelScroll.class) +@WebMvcTest(ChannelScrollController.class) @TestPropertySource(value = "classpath:application_test.properties") -class ChannelScrollIT { +class ChannelScrollControllerIT { - @Autowired ChannelScroll channelScroll; + @Autowired IChannelScroll channelScroll; @Autowired ChannelRepository channelRepository; @@ -29,17 +35,17 @@ class ChannelScrollIT { @Autowired ElasticConfig esService; - @Autowired PopulateService populateService; + @Autowired PopulateDBConfiguration populateDBConfiguration; @BeforeEach public void setup() throws InterruptedException { - populateService.createDB(1); + populateDBConfiguration.createDB(1); Thread.sleep(10000); } @AfterEach public void cleanup() throws InterruptedException { - populateService.cleanupDB(); + populateDBConfiguration.cleanupDB(); } @BeforeAll @@ -63,9 +69,9 @@ void tearDown() throws IOException { void searchNameTest() throws InterruptedException { List channelNames = Arrays.asList( - populateService + populateDBConfiguration .getChannelList() - .toArray(new String[populateService.getChannelList().size()])); + .toArray(new String[populateDBConfiguration.getChannelList().size()])); MultiValueMap searchParameters = new LinkedMultiValueMap(); // Search for a single unique channel diff --git a/src/test/java/org/phoebus/channelfinder/ChannelScrollSearchIT.java b/src/test/java/org/phoebus/channelfinder/ChannelScrollControllerSearchIT.java similarity index 89% rename from src/test/java/org/phoebus/channelfinder/ChannelScrollSearchIT.java rename to src/test/java/org/phoebus/channelfinder/ChannelScrollControllerSearchIT.java index c97c2c44..24907f64 100644 --- a/src/test/java/org/phoebus/channelfinder/ChannelScrollSearchIT.java +++ b/src/test/java/org/phoebus/channelfinder/ChannelScrollControllerSearchIT.java @@ -9,8 +9,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; +import org.phoebus.channelfinder.configuration.PopulateDBConfiguration; import org.phoebus.channelfinder.entity.Scroll; -import org.phoebus.channelfinder.example.PopulateService; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; +import org.phoebus.channelfinder.rest.api.IChannelScroll; +import org.phoebus.channelfinder.rest.controller.ChannelScrollController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.TestPropertySource; @@ -18,29 +23,30 @@ import org.springframework.util.MultiValueMap; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@WebMvcTest(ChannelScroll.class) +@WebMvcTest(ChannelScrollController.class) @TestPropertySource(value = "classpath:application_test.properties") -class ChannelScrollSearchIT { +class ChannelScrollControllerSearchIT { - private static final Logger logger = Logger.getLogger(ChannelScrollSearchIT.class.getName()); + private static final Logger logger = + Logger.getLogger(ChannelScrollControllerSearchIT.class.getName()); - @Autowired ChannelScroll channelScroll; + @Autowired IChannelScroll channelScroll; @Autowired TagRepository tagRepository; @Autowired PropertyRepository propertyRepository; @Autowired ElasticConfig esService; - @Autowired PopulateService populateService; + @Autowired PopulateDBConfiguration populateDBConfiguration; @BeforeEach public void setup() throws InterruptedException { - populateService.createDB(1); + populateDBConfiguration.createDB(1); Thread.sleep(10000); } @AfterEach public void cleanup() throws InterruptedException { - populateService.cleanupDB(); + populateDBConfiguration.cleanupDB(); Thread.sleep(10000); } diff --git a/src/test/java/org/phoebus/channelfinder/ChannelValidationIT.java b/src/test/java/org/phoebus/channelfinder/ChannelValidationIT.java index fb298792..dc992ddb 100644 --- a/src/test/java/org/phoebus/channelfinder/ChannelValidationIT.java +++ b/src/test/java/org/phoebus/channelfinder/ChannelValidationIT.java @@ -10,9 +10,15 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; +import org.phoebus.channelfinder.rest.api.IChannel; +import org.phoebus.channelfinder.rest.controller.ChannelController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; @@ -20,12 +26,12 @@ import org.springframework.web.server.ResponseStatusException; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@WebMvcTest(ChannelManager.class) +@WebMvcTest(ChannelController.class) @WithMockUser(roles = "CF-ADMINS") @TestPropertySource(value = "classpath:application_test.properties") class ChannelValidationIT { - @Autowired ChannelManager channelManager; + @Autowired IChannel channelManager; @Autowired TagRepository tagRepository; diff --git a/src/test/java/org/phoebus/channelfinder/ElasticConfigIT.java b/src/test/java/org/phoebus/channelfinder/ElasticConfigIT.java index b242a6ec..a731f13e 100644 --- a/src/test/java/org/phoebus/channelfinder/ElasticConfigIT.java +++ b/src/test/java/org/phoebus/channelfinder/ElasticConfigIT.java @@ -1,6 +1,7 @@ package org.phoebus.channelfinder; import java.io.IOException; +import org.phoebus.channelfinder.configuration.ElasticConfig; public class ElasticConfigIT { diff --git a/src/test/java/org/phoebus/channelfinder/MetricsServiceIT.java b/src/test/java/org/phoebus/channelfinder/MetricsServiceIT.java index c222dc23..ed89133f 100644 --- a/src/test/java/org/phoebus/channelfinder/MetricsServiceIT.java +++ b/src/test/java/org/phoebus/channelfinder/MetricsServiceIT.java @@ -12,10 +12,15 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; +import org.phoebus.channelfinder.configuration.PopulateDBConfiguration; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; -import org.phoebus.channelfinder.example.PopulateService; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.repository.TagRepository; +import org.phoebus.channelfinder.service.MetricsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -53,7 +58,7 @@ class MetricsServiceIT { @Autowired ElasticConfig esService; - @Autowired PopulateService populateService; + @Autowired PopulateDBConfiguration populateDBConfiguration; @Autowired MetricsService metricsService; diff --git a/src/test/java/org/phoebus/channelfinder/MetricsServiceTest.java b/src/test/java/org/phoebus/channelfinder/MetricsServiceTest.java index b9d45136..8bd08413 100644 --- a/src/test/java/org/phoebus/channelfinder/MetricsServiceTest.java +++ b/src/test/java/org/phoebus/channelfinder/MetricsServiceTest.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; +import org.phoebus.channelfinder.service.MetricsService; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/src/test/java/org/phoebus/channelfinder/PropertyManagerIT.java b/src/test/java/org/phoebus/channelfinder/PropertyControllerIT.java similarity index 99% rename from src/test/java/org/phoebus/channelfinder/PropertyManagerIT.java rename to src/test/java/org/phoebus/channelfinder/PropertyControllerIT.java index 3a425320..0923c1c9 100644 --- a/src/test/java/org/phoebus/channelfinder/PropertyManagerIT.java +++ b/src/test/java/org/phoebus/channelfinder/PropertyControllerIT.java @@ -15,9 +15,14 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; +import org.phoebus.channelfinder.rest.api.IProperty; +import org.phoebus.channelfinder.rest.controller.PropertyController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; @@ -27,12 +32,12 @@ import org.springframework.web.server.ResponseStatusException; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@WebMvcTest(PropertyManager.class) // TODO Somehow creating one +@WebMvcTest(PropertyController.class) // TODO Somehow creating one @WithMockUser(roles = "CF-ADMINS") @TestPropertySource(value = "classpath:application_test.properties") -class PropertyManagerIT { +class PropertyControllerIT { - @Autowired PropertyManager propertyManager; + @Autowired IProperty propertyManager; @Autowired PropertyRepository propertyRepository; diff --git a/src/test/java/org/phoebus/channelfinder/PropertyRepositoryIT.java b/src/test/java/org/phoebus/channelfinder/PropertyRepositoryIT.java index 38cd4f81..83ff891e 100644 --- a/src/test/java/org/phoebus/channelfinder/PropertyRepositoryIT.java +++ b/src/test/java/org/phoebus/channelfinder/PropertyRepositoryIT.java @@ -13,9 +13,12 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.PropertyRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.TestPropertySource; diff --git a/src/test/java/org/phoebus/channelfinder/PropertyValidationIT.java b/src/test/java/org/phoebus/channelfinder/PropertyValidationIT.java index 3c060f8b..530248a2 100644 --- a/src/test/java/org/phoebus/channelfinder/PropertyValidationIT.java +++ b/src/test/java/org/phoebus/channelfinder/PropertyValidationIT.java @@ -9,9 +9,13 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.rest.api.IProperty; +import org.phoebus.channelfinder.rest.controller.PropertyController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; @@ -19,12 +23,12 @@ import org.springframework.web.server.ResponseStatusException; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@WebMvcTest(PropertyManager.class) +@WebMvcTest(PropertyController.class) @WithMockUser(roles = "CF-ADMINS") @TestPropertySource(value = "classpath:application_test.properties") class PropertyValidationIT { - @Autowired PropertyManager propertyManager; + @Autowired IProperty propertyManager; @Autowired ChannelRepository channelRepository; diff --git a/src/test/java/org/phoebus/channelfinder/TagManagerIT.java b/src/test/java/org/phoebus/channelfinder/TagControllerIT.java similarity index 98% rename from src/test/java/org/phoebus/channelfinder/TagManagerIT.java rename to src/test/java/org/phoebus/channelfinder/TagControllerIT.java index 5635b846..951b1e3b 100644 --- a/src/test/java/org/phoebus/channelfinder/TagManagerIT.java +++ b/src/test/java/org/phoebus/channelfinder/TagControllerIT.java @@ -16,8 +16,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.TagRepository; +import org.phoebus.channelfinder.rest.api.ITag; +import org.phoebus.channelfinder.rest.controller.TagController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; @@ -28,20 +33,20 @@ import org.springframework.web.server.ResponseStatusException; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@WebMvcTest(TagManager.class) +@WebMvcTest(TagController.class) @WithMockUser(roles = "CF-ADMINS") @ContextConfiguration(classes = {TagRepository.class, ElasticConfig.class}) @TestPropertySource(value = "classpath:application_test.properties") -class TagManagerIT { +class TagControllerIT { - @Autowired TagManager tagManager; + @Autowired ITag tagManager; @Autowired TagRepository tagRepository; @Autowired ChannelRepository channelRepository; @Autowired ElasticConfig esService; - private static final Logger logger = Logger.getLogger(TagManagerIT.class.getName()); + private static final Logger logger = Logger.getLogger(TagControllerIT.class.getName()); @AfterAll void tearDown() throws IOException { diff --git a/src/test/java/org/phoebus/channelfinder/TagRepositoryIT.java b/src/test/java/org/phoebus/channelfinder/TagRepositoryIT.java index 10c37a01..df0e9d42 100644 --- a/src/test/java/org/phoebus/channelfinder/TagRepositoryIT.java +++ b/src/test/java/org/phoebus/channelfinder/TagRepositoryIT.java @@ -12,8 +12,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.repository.TagRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.TestPropertySource; diff --git a/src/test/java/org/phoebus/channelfinder/TagValidationIT.java b/src/test/java/org/phoebus/channelfinder/TagValidationIT.java index aa05276e..77a9b33f 100644 --- a/src/test/java/org/phoebus/channelfinder/TagValidationIT.java +++ b/src/test/java/org/phoebus/channelfinder/TagValidationIT.java @@ -9,8 +9,12 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.configuration.ElasticConfig; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.repository.ChannelRepository; +import org.phoebus.channelfinder.rest.api.ITag; +import org.phoebus.channelfinder.rest.controller.TagController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; @@ -18,12 +22,12 @@ import org.springframework.web.server.ResponseStatusException; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@WebMvcTest(TagManager.class) +@WebMvcTest(TagController.class) @WithMockUser(roles = "CF-ADMINS") @TestPropertySource(value = "classpath:application_test.properties") class TagValidationIT { - @Autowired TagManager tagManager; + @Autowired ITag tagManager; @Autowired ElasticConfig esService; @Autowired ChannelRepository channelRepository; diff --git a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderChannelsIT.java b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderChannelsIT.java index bc0925c7..b0a60e1b 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderChannelsIT.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderChannelsIT.java @@ -26,18 +26,20 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.phoebus.channelfinder.common.CFResourceDescriptors; import org.phoebus.channelfinder.docker.ITUtil.AuthorizationChoice; import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.rest.controller.ChannelController; import org.testcontainers.containers.ComposeContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; /** * Integration tests for ChannelFinder and Elasticsearch with focus on usage of {@link - * org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. + * CFResourceDescriptors#CHANNEL_RESOURCE_URI}. * * @author Lars Johansson - * @see org.phoebus.channelfinder.ChannelManager + * @see ChannelController * @see org.phoebus.channelfinder.docker.ITTestFixture * @see org.phoebus.channelfinder.docker.ITUtil * @see org.phoebus.channelfinder.docker.ITUtilChannels @@ -161,7 +163,7 @@ void channelfinderUp() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannelRetrieveCheck() { // what @@ -172,7 +174,7 @@ void handleChannelRetrieveCheck() { ITUtilChannels.assertRetrieveChannel("/c11", HttpURLConnection.HTTP_NOT_FOUND); } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleChannelDeleteCheck() { // what @@ -196,7 +198,7 @@ void handleChannelDeleteCheck() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannelCreateUpdateCheckJson() { // what @@ -292,7 +294,7 @@ void handleChannelCreateUpdateCheckJson() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannelCreateUpdateCheck() { // what @@ -375,7 +377,7 @@ void handleChannelCreateUpdateCheck() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannel() { // what @@ -408,7 +410,7 @@ void handleChannel() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannel2() { // what @@ -445,7 +447,7 @@ void handleChannel2() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannel3RenameOwner() { // what @@ -476,7 +478,7 @@ void handleChannel3RenameOwner() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannel4ReplaceNonExisting() { // what @@ -503,7 +505,7 @@ void handleChannel4ReplaceNonExisting() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannelsCreateUpdateCheck() { // what @@ -624,7 +626,7 @@ void handleChannelsCreateUpdateCheck() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannels() { // what @@ -693,7 +695,7 @@ void handleChannels() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannels2ReplaceNonExisting() { // what @@ -762,7 +764,7 @@ void handleChannels2ReplaceNonExisting() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#CHANNEL_RESOURCE_URI}. */ @Test void handleChannels3QueryByPattern() { // what diff --git a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderPropertiesIT.java b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderPropertiesIT.java index cb0118e4..9f1c934a 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderPropertiesIT.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderPropertiesIT.java @@ -26,19 +26,21 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.phoebus.channelfinder.common.CFResourceDescriptors; import org.phoebus.channelfinder.docker.ITUtil.AuthorizationChoice; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; +import org.phoebus.channelfinder.rest.controller.PropertyController; import org.testcontainers.containers.ComposeContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; /** * Integration tests for ChannelFinder and Elasticsearch with focus on usage of {@link - * org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. + * CFResourceDescriptors#PROPERTY_RESOURCE_URI}. * * @author Lars Johansson - * @see org.phoebus.channelfinder.PropertyManager + * @see PropertyController * @see org.phoebus.channelfinder.docker.ITUtil * @see org.phoebus.channelfinder.docker.ITUtilProperties */ @@ -166,7 +168,7 @@ void channelfinderUp() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handlePropertyRetrieveCheck() { // what @@ -177,7 +179,7 @@ void handlePropertyRetrieveCheck() { ITUtilProperties.assertRetrieveProperty("/p11", HttpURLConnection.HTTP_NOT_FOUND); } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handlePropertyRemoveCheck() { // what @@ -201,7 +203,7 @@ void handlePropertyRemoveCheck() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handlePropertyCreateUpdateCheckJson() { // what @@ -309,7 +311,7 @@ void handlePropertyCreateUpdateCheckJson() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handlePropertyCreateUpdateCheck() { // what @@ -389,7 +391,7 @@ void handlePropertyCreateUpdateCheck() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleProperty() { // what @@ -422,7 +424,7 @@ void handleProperty() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleProperty2() { // what @@ -455,7 +457,7 @@ void handleProperty2() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleProperty3RenameOwner() { // what @@ -483,7 +485,7 @@ void handleProperty3RenameOwner() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleProperty4ReplaceNonExisting() { // what @@ -507,7 +509,7 @@ void handleProperty4ReplaceNonExisting() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleProperty5SingleChannel() { // what @@ -603,7 +605,7 @@ void handleProperty5SingleChannel() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleProperty6MultipleChannels() { // what @@ -705,7 +707,7 @@ void handleProperty6MultipleChannels() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handlePropertiesCreateUpdateCheck() { // what @@ -826,7 +828,7 @@ void handlePropertiesCreateUpdateCheck() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleProperties() { // what @@ -902,7 +904,7 @@ void handleProperties() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleProperties2ReplaceNonExisting() { // what diff --git a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderScrollIT.java b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderScrollIT.java index 4132a949..32e96874 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderScrollIT.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderScrollIT.java @@ -24,17 +24,19 @@ import java.net.HttpURLConnection; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; +import org.phoebus.channelfinder.common.CFResourceDescriptors; import org.phoebus.channelfinder.entity.Scroll; +import org.phoebus.channelfinder.rest.controller.ChannelScrollController; import org.testcontainers.containers.ComposeContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; /** * Integration tests for ChannelFinder and Elasticsearch with focus on usage of {@link - * org.phoebus.channelfinder.CFResourceDescriptors#SCROLL_RESOURCE_URI}. + * CFResourceDescriptors#SCROLL_RESOURCE_URI}. * * @author Lars Johansson - * @see org.phoebus.channelfinder.ChannelScroll + * @see ChannelScrollController * @see org.phoebus.channelfinder.docker.ITUtil * @see org.phoebus.channelfinder.docker.ITUtilScroll */ @@ -85,7 +87,7 @@ void channelfinderUp() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#SCROLL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#SCROLL_RESOURCE_URI}. */ @Test void handleScrollQueryChannels() { // what @@ -101,7 +103,7 @@ void handleScrollQueryChannels() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#SCROLL_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#SCROLL_RESOURCE_URI}. */ @Test void handleScrollContinueChannelsQuery() { // what @@ -116,7 +118,7 @@ void handleScrollContinueChannelsQuery() { } /** - * Test {@link org.phoebus.channelfinder.CFResourceDescriptors#SCROLL_RESOURCE_URI}. + * Test {@link CFResourceDescriptors#SCROLL_RESOURCE_URI}. * * @see ChannelFinderChannelsIT#handleChannels3QueryByPattern() * @see ITTestFixture diff --git a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderTagsIT.java b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderTagsIT.java index 1ca5c35e..abe968c9 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderTagsIT.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderTagsIT.java @@ -26,19 +26,21 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.phoebus.channelfinder.common.CFResourceDescriptors; import org.phoebus.channelfinder.docker.ITUtil.AuthorizationChoice; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.rest.controller.TagController; import org.testcontainers.containers.ComposeContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; /** * Integration tests for ChannelFinder and Elasticsearch with focus on usage of {@link - * org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. + * CFResourceDescriptors#TAG_RESOURCE_URI}. * * @author Lars Johansson - * @see org.phoebus.channelfinder.TagManager + * @see TagController * @see org.phoebus.channelfinder.docker.ITUtil * @see org.phoebus.channelfinder.docker.ITUtilTags */ @@ -151,7 +153,7 @@ void channelfinderUp() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTagRetrieveCheck() { // what @@ -162,7 +164,7 @@ void handleTagRetrieveCheck() { ITUtilTags.assertRetrieveTag("/t11", HttpURLConnection.HTTP_NOT_FOUND); } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTagRemoveCheck() { // what @@ -186,7 +188,7 @@ void handleTagRemoveCheck() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTagCreateUpdateCheckJson() { // what @@ -292,7 +294,7 @@ void handleTagCreateUpdateCheckJson() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTagCreateUpdateCheck() { // what @@ -360,7 +362,7 @@ void handleTagCreateUpdateCheck() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTag() { // what @@ -391,7 +393,7 @@ void handleTag() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTag2() { // what @@ -423,7 +425,7 @@ void handleTag2() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTag3RenameOwner() { // what @@ -451,7 +453,7 @@ void handleTag3RenameOwner() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTag4ReplaceNonExisting() { // what @@ -475,7 +477,7 @@ void handleTag4ReplaceNonExisting() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleTag5SingleChannel() { // what @@ -569,7 +571,7 @@ void handleTag5SingleChannel() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleTag6MultipleChannels() { // what @@ -664,7 +666,7 @@ void handleTag6MultipleChannels() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTagsCreateUpdateCheck() { // what @@ -782,7 +784,7 @@ void handleTagsCreateUpdateCheck() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTags() { // what @@ -853,7 +855,7 @@ void handleTags() { } } - /** Test {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. */ + /** Test {@link CFResourceDescriptors#TAG_RESOURCE_URI}. */ @Test void handleTags2ReplaceNonExisting() { // what diff --git a/src/test/java/org/phoebus/channelfinder/epics/EpicsRPCRequestIT.java b/src/test/java/org/phoebus/channelfinder/epics/EpicsRPCRequestIT.java index f7030aad..3ee3bc8a 100644 --- a/src/test/java/org/phoebus/channelfinder/epics/EpicsRPCRequestIT.java +++ b/src/test/java/org/phoebus/channelfinder/epics/EpicsRPCRequestIT.java @@ -15,12 +15,14 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; -import org.phoebus.channelfinder.ChannelManager; -import org.phoebus.channelfinder.PropertyManager; -import org.phoebus.channelfinder.TagManager; +import org.phoebus.channelfinder.common.NTXmlUtil; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.rest.api.IChannel; +import org.phoebus.channelfinder.rest.api.IProperty; +import org.phoebus.channelfinder.rest.api.ITag; +import org.phoebus.channelfinder.service.ChannelFinderEpicsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; @@ -59,11 +61,11 @@ public static void cleanup() { pvaClient.getChannel(ChannelFinderEpicsService.SERVICE_DESC); ; - @Autowired ChannelManager channelManager; + @Autowired IChannel channelManager; - @Autowired PropertyManager propertyManager; + @Autowired IProperty propertyManager; - @Autowired TagManager tagManager; + @Autowired ITag tagManager; @Test void testRPCService() throws ExecutionException, InterruptedException, TimeoutException { diff --git a/src/test/java/org/phoebus/channelfinder/performance/ExistsPerformanceIT.java b/src/test/java/org/phoebus/channelfinder/performance/ExistsPerformanceIT.java index b25ee374..a46667cb 100644 --- a/src/test/java/org/phoebus/channelfinder/performance/ExistsPerformanceIT.java +++ b/src/test/java/org/phoebus/channelfinder/performance/ExistsPerformanceIT.java @@ -3,8 +3,8 @@ import com.google.common.collect.Lists; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.phoebus.channelfinder.ChannelRepository; -import org.phoebus.channelfinder.example.PopulateService; +import org.phoebus.channelfinder.configuration.PopulateDBConfiguration; +import org.phoebus.channelfinder.repository.ChannelRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -16,7 +16,7 @@ @WebMvcTest(ChannelRepository.class) class ExistsPerformanceIT { - @Autowired PopulateService service; + @Autowired PopulateDBConfiguration service; @Autowired ChannelRepository channelRepository; diff --git a/src/test/java/org/phoebus/channelfinder/performance/PopulateServiceIT.java b/src/test/java/org/phoebus/channelfinder/performance/PopulateDBConfigurationIT.java similarity index 69% rename from src/test/java/org/phoebus/channelfinder/performance/PopulateServiceIT.java rename to src/test/java/org/phoebus/channelfinder/performance/PopulateDBConfigurationIT.java index 4a393146..fa2290a2 100644 --- a/src/test/java/org/phoebus/channelfinder/performance/PopulateServiceIT.java +++ b/src/test/java/org/phoebus/channelfinder/performance/PopulateDBConfigurationIT.java @@ -2,8 +2,8 @@ import java.net.URL; import org.junit.jupiter.api.Test; -import org.phoebus.channelfinder.AuthorizationService; -import org.phoebus.channelfinder.example.PopulateService; +import org.phoebus.channelfinder.configuration.PopulateDBConfiguration; +import org.phoebus.channelfinder.service.AuthorizationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; @@ -12,9 +12,9 @@ /** An class for creating the example database and testing the speed. */ @WebMvcTest(AuthorizationService.class) @TestPropertySource(value = "classpath:performance_application.properties") -class PopulateServiceIT { +class PopulateDBConfigurationIT { - @Autowired PopulateService populateService; + @Autowired PopulateDBConfiguration populateDBConfiguration; @Test @WithMockUser(username = "admin", roles = "CF-ADMINS") @@ -22,16 +22,16 @@ void testCreateTagsAndProperties() { final URL tagResource = getClass().getResource("/perf_tags.json"); final URL propertyResource = getClass().getResource("/perf_properties.json"); - populateService.createTagsAndProperties(tagResource, propertyResource); + populateDBConfiguration.createTagsAndProperties(tagResource, propertyResource); } @Test void testCreateDB() { - populateService.createDB(); + populateDBConfiguration.createDB(); } @Test void testCleanUpDB() { - populateService.cleanupDB(); + populateDBConfiguration.cleanupDB(); } } diff --git a/src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorManagerIT.java b/src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorControllerIT.java similarity index 91% rename from src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorManagerIT.java rename to src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorControllerIT.java index 71319021..020a5eac 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorManagerIT.java +++ b/src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorControllerIT.java @@ -9,9 +9,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.phoebus.channelfinder.CFResourceDescriptors; -import org.phoebus.channelfinder.ChannelScroll; +import org.phoebus.channelfinder.common.CFResourceDescriptors; import org.phoebus.channelfinder.entity.Scroll; +import org.phoebus.channelfinder.rest.api.IChannelScroll; +import org.phoebus.channelfinder.rest.controller.ChannelProcessorController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -23,17 +24,17 @@ import org.springframework.util.Base64Utils; @ExtendWith(SpringExtension.class) -@WebMvcTest(ChannelProcessorManager.class) +@WebMvcTest(ChannelProcessorController.class) @TestPropertySource( value = "classpath:application_test.properties", properties = {"elasticsearch.create.indices = false"}) -class ChannelProcessorManagerIT { +class ChannelProcessorControllerIT { protected static final String AUTHORIZATION = "Basic " + Base64Utils.encodeToString("admin:adminPass".getBytes()); @Autowired protected MockMvc mockMvc; - @MockBean ChannelScroll channelScroll; + @MockBean IChannelScroll channelScroll; @Test void testProcessorCount() throws Exception { diff --git a/src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorServiceTest.java b/src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorServiceTest.java index 88454b78..bbd47956 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorServiceTest.java +++ b/src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorServiceTest.java @@ -8,7 +8,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.phoebus.channelfinder.configuration.ChannelProcessor; import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.service.ChannelProcessorService; +import org.phoebus.channelfinder.service.model.archiver.ChannelProcessorInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; diff --git a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorIT.java b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorIT.java index 8fa12e59..665f14c2 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorIT.java +++ b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorIT.java @@ -19,9 +19,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.phoebus.channelfinder.configuration.AAChannelProcessor; +import org.phoebus.channelfinder.configuration.ChannelProcessor; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; -import org.phoebus.channelfinder.processors.ChannelProcessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.TestPropertySource; diff --git a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorMultiArchiverIT.java b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorMultiArchiverIT.java index baeb914a..763ed5df 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorMultiArchiverIT.java +++ b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorMultiArchiverIT.java @@ -24,7 +24,9 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.phoebus.channelfinder.configuration.AAChannelProcessor; import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.service.model.archiver.aa.ArchiveAction; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.TestPropertySource; diff --git a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorMultiIT.java b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorMultiIT.java index dbd2d241..593b2b02 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorMultiIT.java +++ b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorMultiIT.java @@ -24,7 +24,9 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.phoebus.channelfinder.configuration.AAChannelProcessor; import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.service.model.archiver.aa.ArchiveAction; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.TestPropertySource; diff --git a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorNoDefaultIT.java b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorNoDefaultIT.java index 69125930..8ed2eb00 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorNoDefaultIT.java +++ b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorNoDefaultIT.java @@ -15,6 +15,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.phoebus.channelfinder.configuration.AAChannelProcessor; import org.phoebus.channelfinder.entity.Channel; import org.phoebus.channelfinder.entity.Property; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorNoPauseIT.java b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorNoPauseIT.java index adc10c8d..aeb04572 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorNoPauseIT.java +++ b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorNoPauseIT.java @@ -15,6 +15,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.phoebus.channelfinder.configuration.AAChannelProcessor; import org.phoebus.channelfinder.entity.Channel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; diff --git a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorStatusPauseIT.java b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorStatusPauseIT.java index 88885852..5b8fdbba 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorStatusPauseIT.java +++ b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorStatusPauseIT.java @@ -15,6 +15,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.phoebus.channelfinder.configuration.AAChannelProcessor; import org.phoebus.channelfinder.entity.Channel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; diff --git a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorTagPauseIT.java b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorTagPauseIT.java index 36d8988e..b6b9a838 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorTagPauseIT.java +++ b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorTagPauseIT.java @@ -15,6 +15,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.phoebus.channelfinder.configuration.AAChannelProcessor; import org.phoebus.channelfinder.entity.Channel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; diff --git a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorTest.java b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorTest.java index 4bbc5113..f3508553 100644 --- a/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorTest.java +++ b/src/test/java/org/phoebus/channelfinder/processors/aa/AAChannelProcessorTest.java @@ -11,6 +11,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.phoebus.channelfinder.service.model.archiver.aa.ArchivePVOptions; class AAChannelProcessorTest { diff --git a/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md b/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md index cde23d94..d0bb2d48 100644 --- a/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md +++ b/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md @@ -140,7 +140,7 @@ class ChannelFinderPropertiesIT { } /** - * Test {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. + * Test {@link org.phoebus.channelfinder.common.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. */ @Test void handleProperty() { diff --git a/src/test/resources/logging.properties b/src/test/resources/logging.properties index 50521853..3ca30b45 100644 --- a/src/test/resources/logging.properties +++ b/src/test/resources/logging.properties @@ -2,7 +2,7 @@ handlers= java.util.logging.ConsoleHandler .level = SEVERE -org.phoebus.channelfinder.ChannelManager = SEVERE +org.phoebus.channelfinder.rest.controller.ChannelController = SEVERE o.p.channelfinder.ChannelManager = SEVERE -org.phoebus.channelfinder.ChannelRepository = SEVERE +org.phoebus.channelfinder.repository.ChannelRepository = SEVERE o.p.channelfinder.ChannelRepository = SEVERE \ No newline at end of file