Repository: logging-log4j-audit Updated Branches: refs/heads/master 3ffa62060 -> d5b3c5bab
Add Catalog service methods to AuditService Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/commit/d5b3c5ba Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/tree/d5b3c5ba Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/diff/d5b3c5ba Branch: refs/heads/master Commit: d5b3c5babb6c3c325aa3c2e47c054b8996108d3f Parents: 3ffa620 Author: Ralph Goers <[email protected]> Authored: Wed Sep 6 17:21:13 2017 -0700 Committer: Ralph Goers <[email protected]> Committed: Wed Sep 6 17:21:13 2017 -0700 ---------------------------------------------------------------------- .../logging/log4j/audit/constant/Column.java | 102 ------ .../log4j/audit/constant/Environment.java | 45 --- .../log4j/audit/constant/QueryParameter.java | 41 --- log4j-audit/log4j-audit-war/pom.xml | 9 +- .../service/controller/CatalogController.java | 320 +++++++++++++++++++ .../RestResponseEntityExceptionHandler.java | 3 + log4j-catalog/log4j-catalog-api/pom.xml | 4 - .../logging/log4j/catalog/api/Attribute.java | 4 +- .../logging/log4j/catalog/api/Category.java | 4 +- .../apache/logging/log4j/catalog/api/Event.java | 4 +- .../logging/log4j/catalog/api/Product.java | 6 +- .../log4j/catalog/api/constant/Constants.java | 28 ++ log4j-catalog/log4j-catalog-git/pom.xml | 13 - log4j-catalog/log4j-catalog-jpa/pom.xml | 8 - .../jpa/dao/PagingAndSortingRepository.java | 9 + .../catalog/jpa/service/AttributeService.java | 4 + .../jpa/service/AttributeServiceImpl.java | 18 ++ .../catalog/jpa/service/CategoryService.java | 4 + .../jpa/service/CategoryServiceImpl.java | 18 ++ .../log4j/catalog/jpa/service/EventService.java | 3 + .../catalog/jpa/service/EventServiceImpl.java | 18 ++ .../catalog/jpa/service/ProductService.java | 4 + .../catalog/jpa/service/ProductServiceImpl.java | 19 ++ log4j-catalog/log4j-catalog-war/pom.xml | 5 - 24 files changed, 465 insertions(+), 228 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/Column.java ---------------------------------------------------------------------- diff --git a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/Column.java b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/Column.java deleted file mode 100644 index a9f112f..0000000 --- a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/Column.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.audit.constant; - -/** - * The Class Column. - */ -public class Column { - - /** The Constant PREFIX. */ - public static final String REQCTX_PREFIX = "ReqCtx_"; - - /** The Constant ID. */ - public static final String ID = REQCTX_PREFIX + "id"; - - /** The Constant BCID. */ - public static final String BCID = REQCTX_PREFIX + "bcId"; - - /** The Constant GUID. */ - public static final String GUID = "guId"; - - /** The Constant USER_PRODUCT. */ - public static final String USER_PRODUCT = REQCTX_PREFIX + "userProduct"; - - /** The Constant IP_ADDRESS. */ - public static final String IP_ADDRESS = REQCTX_PREFIX + "ipAddress"; - - /** The Constant SESSION_ID. */ - public static final String SESSION_ID = REQCTX_PREFIX + "sessionId"; - - /** The Constant USER_ID. */ - public static final String USER_ID = REQCTX_PREFIX + "userId"; - - /** The Constant HOST_NAME. */ - public static final String HOST_NAME = REQCTX_PREFIX + "hostName"; - - /** The Constant TIMEZONE_OFFSET. */ - public static final String TIMEZONE_OFFSET = REQCTX_PREFIX + "tzOffset"; - - /** The Constant REGION. */ - public static final String REGION = REQCTX_PREFIX + "region"; - - /** The Constant CANONICAL_ID. */ - public static final String CANONICAL_ID = REQCTX_PREFIX + "canonicalId"; - - /** The Constant BC_INDEX. */ - public static final String BC_INDEX = REQCTX_PREFIX + "bcIndex"; - - /** The Constant OFFERING_ID. */ - public static final String OFFERING_ID = REQCTX_PREFIX + "offeringId"; - - /** The Constant APP_ID. */ - public static final String APP_ID = REQCTX_PREFIX + "appId"; - - public static final String LOGIN_ID = REQCTX_PREFIX + "loginId"; - - public static final String USER_AGENT = REQCTX_PREFIX + "userAgent"; - - /** The Constant TIME_STAMP. */ - public static final String TIME_STAMP = "timeStamp"; - - /** The Constant EVENT_TYPE. */ - public static final String EVENT_TYPE = "eventType"; - - /** The Constant MEMBER. */ - public static final String MEMBER = "member"; - - public static final String HOLDING_CO_ID = "holdingCoId"; - - /** The Constant EVENT_ID. */ - public static final String EVENT_ID = "eventId"; - - public static final String FEATURE_NAME = REQCTX_PREFIX + "featureName"; - - public static final String COMPLETION_STATUS = "completionStatus"; - - public static final String RAW_DATA = "rawData"; - - public static final String NONRC_IP_ADDRESS = "ipAddress"; - - public static final String NONRC_SESSION_ID = "sessionId"; - - public static final String NONRC_USER_AGENT = "userAgent"; - - public static final String APPLICATION_ID = "applicationId"; - - public static final String NONRC_USER_PRODUCT = "userProduct"; -} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/Environment.java ---------------------------------------------------------------------- diff --git a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/Environment.java b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/Environment.java deleted file mode 100644 index dcbda6b..0000000 --- a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/Environment.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.audit.constant; - -/** - * Various environments applications run in. - */ -public enum Environment { - - PROD("Production"), PRE_PROD("Pre-Production"), UAT("UserAcceptance"), BETA("Beta"), - RC("ReleaseCandidate"), STAGING("Staging"), - DEV("Development"), DEVQA("DevelopmentQA"), QA("QA"), PERF("Performance"); - private final String name; - - private Environment(String name) { - this.name = name; - } - - public String toString() { - return this.name; - } - - public static Environment getByName(String name) { - for (Environment region : values()) { - if (region.name.equals(name)) { - return region; - } - } - return null; - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/QueryParameter.java ---------------------------------------------------------------------- diff --git a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/QueryParameter.java b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/QueryParameter.java deleted file mode 100644 index 742345c..0000000 --- a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/constant/QueryParameter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.audit.constant; - -public class QueryParameter { - public static final String EVENT = "event"; - public static final String ATTRIBUTE = "attribute"; - public static final String ATTRIBUTE_DETAILS = "attributeDetails"; - public static final String CATEGORY = "category"; - - public static final String START_DATE = "startDate"; - public static final String END_DATE = "endDate"; - public static final String USER_TYPE = "userType"; - public static final String LIMIT = "limit"; - public static final String METHOD_NAME = "method"; - public static final String LATEST_FIRST = "latestFirst"; - public static final String START_KEY = "startKey"; - public static final String NEXT_GUID = "nextGuid"; - public static final String LAST_GUID = "lastGuid"; - public static final String COUNT_ONLY = "countOnly"; - public static final String PAGE_NUMBER = "pageNumber"; - public static final String BATCH_REQ_TOKEN = "batchReqToken"; - public static final String COUNT_REQUIRED = "countRequired"; - public static final String CLIENT_APP = "clientApp"; - public static final String EVENT_TYPE = "eventType"; - public static final String REGION = "region"; -} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-audit/log4j-audit-war/pom.xml ---------------------------------------------------------------------- diff --git a/log4j-audit/log4j-audit-war/pom.xml b/log4j-audit/log4j-audit-war/pom.xml index efab88b..5eff84f 100644 --- a/log4j-audit/log4j-audit-war/pom.xml +++ b/log4j-audit/log4j-audit-war/pom.xml @@ -53,6 +53,10 @@ <artifactId>log4j-catalog-api</artifactId> </dependency> <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-catalog-jpa</artifactId> + </dependency> + <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </dependency> @@ -91,11 +95,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>javax</groupId> - <artifactId>javaee-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/CatalogController.java ---------------------------------------------------------------------- diff --git a/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/CatalogController.java b/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/CatalogController.java new file mode 100644 index 0000000..cc7dfe9 --- /dev/null +++ b/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/CatalogController.java @@ -0,0 +1,320 @@ +package org.apache.logging.log4j.audit.service.controller; + +import javax.annotation.PostConstruct; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.catalog.api.Attribute; +import org.apache.logging.log4j.catalog.api.Category; +import org.apache.logging.log4j.catalog.api.Event; +import org.apache.logging.log4j.catalog.api.Product; +import org.apache.logging.log4j.catalog.api.Versions; +import org.apache.logging.log4j.catalog.jpa.converter.AttributeConverter; +import org.apache.logging.log4j.catalog.jpa.converter.AttributeModelConverter; +import org.apache.logging.log4j.catalog.jpa.converter.CategoryConverter; +import org.apache.logging.log4j.catalog.jpa.converter.CategoryModelConverter; +import org.apache.logging.log4j.catalog.jpa.converter.EventConverter; +import org.apache.logging.log4j.catalog.jpa.converter.EventModelConverter; +import org.apache.logging.log4j.catalog.jpa.converter.ProductConverter; +import org.apache.logging.log4j.catalog.jpa.converter.ProductModelConverter; +import org.apache.logging.log4j.catalog.jpa.model.AttributeModel; +import org.apache.logging.log4j.catalog.jpa.model.CategoryModel; +import org.apache.logging.log4j.catalog.jpa.model.EventModel; +import org.apache.logging.log4j.catalog.jpa.model.ProductModel; +import org.apache.logging.log4j.catalog.jpa.service.AttributeService; +import org.apache.logging.log4j.catalog.jpa.service.CategoryService; +import org.apache.logging.log4j.catalog.jpa.service.EventService; +import org.apache.logging.log4j.catalog.jpa.service.ProductService; +import org.modelmapper.ModelMapper; +import org.modelmapper.TypeToken; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +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 static org.apache.logging.log4j.catalog.api.constant.Constants.DEFAULT_CATALOG; + +@RestController +@RequestMapping(value = "/catalog") +public class CatalogController { + + private static final Logger LOGGER = LogManager.getLogger(CatalogController.class); + + private ModelMapper attributeModelMapper = new ModelMapper(); + private ModelMapper eventModelMapper = new ModelMapper(); + private ModelMapper productModelMapper = new ModelMapper(); + private ModelMapper categoryModelMapper = new ModelMapper(); + + @Autowired + private AttributeService attributeService; + + @Autowired + private AttributeModelConverter attributeModelConverter; + + @Autowired + private AttributeConverter attributeConverter; + + @Autowired + private EventService eventService; + + @Autowired + private EventModelConverter eventModelConverter; + + @Autowired + private EventConverter eventConverter; + + @Autowired + private ProductService productService; + + @Autowired + private ProductModelConverter productModelConverter; + + @Autowired + private ProductConverter productConverter; + + @Autowired + private CategoryService categoryService; + + + @Autowired + private CategoryModelConverter categoryModelConverter; + + @Autowired + private CategoryConverter categoryConverter; + + @PostConstruct + public void init() { + attributeModelMapper.addConverter(attributeModelConverter); + eventModelMapper.addConverter(eventModelConverter); + productModelMapper.addConverter(productModelConverter); + categoryModelMapper.addConverter(categoryModelConverter); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Create a catalog Attribute", notes = "Creates a catalog attribute", tags = {"Catalog"}) + @GetMapping(value = "{catalogId}/attributes") + public ResponseEntity<List<Attribute>> getAttributes(@ApiParam(value = "catalog id", required = true) @PathVariable String catalogId, + @RequestParam(value = "startIndex", required = false) Integer startIndex, + @RequestParam(value = "pageSize", required = false) Integer pageSize, + @RequestParam(value = "sortCol", required= false) String sortColumn, + @RequestParam(value = "sortDir", required = false) String sortDirection) { + Type listType = new TypeToken<List<Attribute>>() { + }.getType(); + List<Attribute> attributes = null; + if (startIndex == null || pageSize == null) { + attributes = attributeModelMapper.map(attributeService.getAttributes(catalogId), listType); + } else { + sortDirection = validateSortDirection(sortDirection); + if (sortColumn == null || sortColumn.length() == 0) { + sortColumn = "name"; + } + int startPage = 0; + if (startIndex > 0) { + startPage = startIndex / pageSize; + } + attributes = attributeModelMapper.map(attributeService.getAttributes(startPage, pageSize, sortColumn, + sortDirection), listType); + } + if (attributes == null) { + attributes = new ArrayList<>(); + } + return new ResponseEntity<>(attributes, HttpStatus.OK); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Create a catalog Attribute", notes = "Creates a catalog attribute", tags = {"Catalog"}) + @GetMapping(value = "{catalogId}/attribute/{name}") + public ResponseEntity<Attribute> getAttribute(@ApiParam(value = "catalog id", required = true) @PathVariable String catalogId, + @ApiParam(value = "attribute name", required = true) @PathVariable String name) { + Optional<AttributeModel> optional = attributeService.getAttribute(catalogId, name); + if (!optional.isPresent()) { + LOGGER.warn("Unable to locate attribute {} in catalog {}", name, catalogId); + return new ResponseEntity(HttpStatus.NOT_FOUND); + } + Attribute attribute = attributeModelConverter.convert(optional.get()); + return new ResponseEntity<>(attribute, HttpStatus.OK); + } + + + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Create a catalog Attribute", notes = "Creates a catalog attribute", tags = {"Catalog"}) + @PostMapping(value = "/attribute", consumes=Versions.V1_0_VALUE, produces=Versions.V1_0_VALUE) + public ResponseEntity<Attribute> createAttribute(@ApiParam(value = "attribute", required = true) @RequestBody Attribute attribute) { + if (attribute.getCatalogId() == null) { + throw new IllegalArgumentException("A catalog id is required."); + } + if (DEFAULT_CATALOG.equals(attribute.getCatalogId())) { + throw new IllegalArgumentException("The default catalog cannot be modified at run time."); + } + AttributeModel model = attributeConverter.convert(attribute); + model = attributeService.saveAttribute(model); + return new ResponseEntity(attributeModelConverter.convert(model), HttpStatus.CREATED); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Update a catalog Attribute", notes = "Updates a catalog attribute", tags = {"Catalog"}) + @PutMapping(value = "/attribute", consumes=Versions.V1_0_VALUE, produces=Versions.V1_0_VALUE) + public ResponseEntity<Attribute> updateAttribute(@ApiParam(value = "attribute", required = true) @RequestBody Attribute attribute) { + if (attribute.getId() == null) { + throw new IllegalArgumentException("An Attribute must have an id to be updated."); + } + if (attribute.getCatalogId() == null) { + throw new IllegalArgumentException("A catalog id is required in the Attribute."); + } + if (DEFAULT_CATALOG.equals(attribute.getCatalogId())) { + throw new IllegalArgumentException("The default catalog cannot be modified at run time."); + } + AttributeModel model = attributeConverter.convert(attribute); + model = attributeService.saveAttribute(model); + return new ResponseEntity(attributeModelConverter.convert(model), HttpStatus.OK); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Deletes a catalog Attribute", notes = "Deletes a catalog attribute", tags = {"Catalog"}) + @DeleteMapping(value = "/attribute/{id}") + public ResponseEntity<?> deleteAttribute(@RequestParam("id") Long attributeId) { + attributeService.deleteAttribute(attributeId); + return new ResponseEntity(HttpStatus.OK); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Create a catalog Event", notes = "Creates a catalog event", tags = {"Catalog"}) + @PostMapping(value = "/event", consumes=Versions.V1_0_VALUE, produces=Versions.V1_0_VALUE) + public ResponseEntity<Attribute> createEvent(@ApiParam(value = "event", required = true) @RequestBody Event event) { + if (event.getCatalogId() == null) { + throw new IllegalArgumentException("A catalog id is required to create an event."); + } + if (DEFAULT_CATALOG.equals(event.getCatalogId())) { + throw new IllegalArgumentException("The default catalog cannot be modified at run time."); + } + EventModel model = eventConverter.convert(event); + model = eventService.saveEvent(model); + return new ResponseEntity(eventModelConverter.convert(model), HttpStatus.CREATED); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Update a catalog Event", notes = "Updates a catalog event", tags = {"Catalog"}) + @PutMapping(value = "/event", consumes=Versions.V1_0_VALUE, produces=Versions.V1_0_VALUE) + public ResponseEntity<Event> updateEvent(@ApiParam(value = "event", required = true) @RequestBody Event event) { + if (event.getCatalogId() == null) { + throw new IllegalArgumentException("A catalog id is required to update an event."); + } + if (DEFAULT_CATALOG.equals(event.getCatalogId())) { + throw new IllegalArgumentException("The default catalog cannot be modified at run time."); + } + EventModel model = eventConverter.convert(event); + model = eventService.saveEvent(model); + return new ResponseEntity(eventModelConverter.convert(model), HttpStatus.OK); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Deletes a catalog event", notes = "Deletes a catalog event", tags = {"Catalog"}) + @DeleteMapping(value = "/event/{id}") + public ResponseEntity<?> deleteEvent(@RequestParam("id") Long eventId) { + eventService.deleteEvent(eventId); + return new ResponseEntity(HttpStatus.OK); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Create a catalog Product", notes = "Creates a catalog product", tags = {"Catalog"}) + @PostMapping(value = "/product", consumes=Versions.V1_0_VALUE, produces=Versions.V1_0_VALUE) + public ResponseEntity<Product> createProduct(@ApiParam(value = "product", required = true) @RequestBody Product product) { + if (product.getCatalogId() == null) { + throw new IllegalArgumentException("A catalog id is required to create a product."); + } + if (DEFAULT_CATALOG.equals(product.getCatalogId())) { + throw new IllegalArgumentException("The default catalog cannot be modified at run time."); + } + ProductModel model = productConverter.convert(product); + model = productService.saveProduct(model); + return new ResponseEntity(productModelConverter.convert(model), HttpStatus.CREATED); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Update a catalog Product", notes = "Updates a catalog event", tags = {"Catalog"}) + @PutMapping(value = "/product", consumes=Versions.V1_0_VALUE, produces=Versions.V1_0_VALUE) + public ResponseEntity<Product> updateProduct(@ApiParam(value = "product", required = true) @RequestBody Product product) { + if (product.getCatalogId() == null) { + throw new IllegalArgumentException("A catalog id is required to update a product."); + } + if (DEFAULT_CATALOG.equals(product.getCatalogId())) { + throw new IllegalArgumentException("The default catalog cannot be modified at run time."); + } + ProductModel model = productConverter.convert(product); + model = productService.saveProduct(model); + return new ResponseEntity(productModelConverter.convert(model), HttpStatus.OK); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Deletes a catalog product", notes = "Deletes a catalog product", tags = {"Catalog"}) + @DeleteMapping(value = "/product/{id}") + public ResponseEntity<?> deleteProduct(@RequestParam("id") Long productId) { + productService.deleteProduct(productId); + return new ResponseEntity(HttpStatus.OK); + } + + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Create a catalog Category", notes = "Creates a catalog category", tags = {"Catalog"}) + @PostMapping(value = "/category", consumes=Versions.V1_0_VALUE, produces=Versions.V1_0_VALUE) + public ResponseEntity<Category> createCategory(@ApiParam(value = "category", required = true) @RequestBody Category category) { + if (category.getCatalogId() == null) { + throw new IllegalArgumentException("A catalog id is required to create a category."); + } + if (DEFAULT_CATALOG.equals(category.getCatalogId())) { + throw new IllegalArgumentException("The default catalog cannot be modified at run time."); + } + CategoryModel model = categoryConverter.convert(category); + model = categoryService.saveCategory(model); + return new ResponseEntity(categoryModelConverter.convert(model), HttpStatus.CREATED); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Update a catalog Category", notes = "Updates a catalog category", tags = {"Catalog"}) + @PutMapping(value = "/category", consumes=Versions.V1_0_VALUE, produces=Versions.V1_0_VALUE) + public ResponseEntity<Category> updateCategory(@ApiParam(value = "category", required = true) @RequestBody Category category) { + if (category.getCatalogId() == null) { + throw new IllegalArgumentException("A catalog id is required to create a category."); + } + if (DEFAULT_CATALOG.equals(category.getCatalogId())) { + throw new IllegalArgumentException("The default catalog cannot be modified at run time."); + } + CategoryModel model = categoryConverter.convert(category); + model = categoryService.saveCategory(model); + return new ResponseEntity(categoryModelConverter.convert(model), HttpStatus.OK); + } + + @ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")}) + @ApiOperation(value = "Deletes a catalog category", notes = "Deletes a catalog category", tags = {"Catalog"}) + @DeleteMapping(value = "/category/{id}") + public ResponseEntity<?> deleteCategory(@RequestParam("id") Long categoryId) { + categoryService.deleteCategory(categoryId); + return new ResponseEntity(HttpStatus.OK); + } + + private String validateSortDirection(String sortDirection) { + if (sortDirection == null) { + sortDirection = "ASC"; + } else if (sortDirection != "ASC" && sortDirection != "DESC") { + LOGGER.warn("Invalid sort direction {}, defaulting to ascending", sortDirection); + sortDirection = "ASC"; + } + return sortDirection; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/RestResponseEntityExceptionHandler.java ---------------------------------------------------------------------- diff --git a/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/RestResponseEntityExceptionHandler.java b/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/RestResponseEntityExceptionHandler.java index 83eae7e..ccb2b15 100644 --- a/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/RestResponseEntityExceptionHandler.java +++ b/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/RestResponseEntityExceptionHandler.java @@ -34,6 +34,9 @@ public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionH @ExceptionHandler({ Exception.class }) @ResponseBody public ResponseEntity<?> handleAnyException(Exception e) { + if (e instanceof IllegalArgumentException) { + return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST); + } return errorResponse(e, HttpStatus.INTERNAL_SERVER_ERROR); } http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-api/pom.xml ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-api/pom.xml b/log4j-catalog/log4j-catalog-api/pom.xml index 9660bca..3e0bcdb 100644 --- a/log4j-catalog/log4j-catalog-api/pom.xml +++ b/log4j-catalog/log4j-catalog-api/pom.xml @@ -97,9 +97,5 @@ <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> </dependency> - <dependency> - <groupId>javax</groupId> - <artifactId>javaee-api</artifactId> - </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Attribute.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Attribute.java b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Attribute.java index cc5fddf..9cffb6c 100644 --- a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Attribute.java +++ b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Attribute.java @@ -21,6 +21,8 @@ import java.util.Set; import com.fasterxml.jackson.annotation.JsonIgnore; +import static org.apache.logging.log4j.catalog.api.constant.Constants.DEFAULT_CATALOG; + /** * A Catalog AttributeDto. */ @@ -46,7 +48,7 @@ public class Attribute implements Serializable { * Set default values. */ public Attribute() { - catalogId = "DEFAULT"; + catalogId = DEFAULT_CATALOG; } /** http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Category.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Category.java b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Category.java index 5f26af9..461f69f 100644 --- a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Category.java +++ b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Category.java @@ -21,6 +21,8 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnore; +import static org.apache.logging.log4j.catalog.api.constant.Constants.DEFAULT_CATALOG; + /** * A Catalog Category. */ @@ -39,7 +41,7 @@ public class Category implements Serializable { * Set default values; */ public Category() { - catalogId = "DEFAULT"; + catalogId = DEFAULT_CATALOG; } /** http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Event.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Event.java b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Event.java index 4c1c582..0809312 100644 --- a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Event.java +++ b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Event.java @@ -22,6 +22,8 @@ import java.util.Set; import com.fasterxml.jackson.annotation.JsonIgnore; +import static org.apache.logging.log4j.catalog.api.constant.Constants.DEFAULT_CATALOG; + /** * Basic attributes common to all events. */ @@ -41,7 +43,7 @@ public class Event implements Serializable { * Set default values. */ public Event() { - catalogId = "DEFAULT"; + catalogId = DEFAULT_CATALOG; } /** http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Product.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Product.java b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Product.java index f9f3737..550d957 100644 --- a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Product.java +++ b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Product.java @@ -16,11 +16,13 @@ */ package org.apache.logging.log4j.catalog.api; +import javax.xml.bind.annotation.XmlType; import java.io.Serializable; import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnore; -import org.apache.logging.log4j.catalog.api.Event; + +import static org.apache.logging.log4j.catalog.api.constant.Constants.DEFAULT_CATALOG; /** @@ -41,7 +43,7 @@ public class Product implements Serializable { * Set default values. */ public Product() { - catalogId = "DEFAULT"; + catalogId = DEFAULT_CATALOG; } /** http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/constant/Constants.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/constant/Constants.java b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/constant/Constants.java new file mode 100644 index 0000000..3b7c31e --- /dev/null +++ b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/constant/Constants.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.catalog.api.constant; + +/** + * Contains constants used in Log4j-Catalog. + */ +public final class Constants { + + private Constants() { + } + + public static final String DEFAULT_CATALOG = "DEFAULT"; +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-git/pom.xml ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-git/pom.xml b/log4j-catalog/log4j-catalog-git/pom.xml index 06b291c..7309422 100644 --- a/log4j-catalog/log4j-catalog-git/pom.xml +++ b/log4j-catalog/log4j-catalog-git/pom.xml @@ -80,19 +80,6 @@ <artifactId>jackson-databind</artifactId> </dependency> <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - </dependency> - <dependency> - <groupId>javax</groupId> - <artifactId>javaee-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/pom.xml ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/pom.xml b/log4j-catalog/log4j-catalog-jpa/pom.xml index 8b94886..b2a1642 100644 --- a/log4j-catalog/log4j-catalog-jpa/pom.xml +++ b/log4j-catalog/log4j-catalog-jpa/pom.xml @@ -79,14 +79,6 @@ <artifactId>jackson-databind</artifactId> </dependency> <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - </dependency> - <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/PagingAndSortingRepository.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/PagingAndSortingRepository.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/PagingAndSortingRepository.java index 2cf4b5b..ee76265 100644 --- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/PagingAndSortingRepository.java +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/PagingAndSortingRepository.java @@ -16,7 +16,10 @@ package org.apache.logging.log4j.catalog.jpa.dao; import java.io.Serializable; +import java.util.List; +import java.util.Optional; +import org.apache.logging.log4j.catalog.jpa.model.EventModel; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -28,4 +31,10 @@ public interface PagingAndSortingRepository<T, ID extends Serializable> extends Iterable<T> findAll(Sort sort); Page<T> findAll(Pageable pageable); + + List<T> findByCatalogId(String catalogId); + + Page<T> findByCatalogId(String catalogId, Pageable pageable); + + Optional<T> findByCatalogIdAndName(String catalogId, String name); } http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeService.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeService.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeService.java index 368153c..92416ce 100644 --- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeService.java +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeService.java @@ -26,8 +26,12 @@ import org.apache.logging.log4j.catalog.jpa.model.AttributeModel; */ public interface AttributeService { List<AttributeModel> getAttributes(int startPage, int itemsPerPage, String sortColumn, String direction); + List<AttributeModel> getAttributes(String catalogId, int startPage, int itemsPerPage, String sortColumn, + String direction); List<AttributeModel> getAttributes(); + List<AttributeModel> getAttributes(String catalogId); Optional<AttributeModel> getAttribute(Long attributeId); + Optional<AttributeModel> getAttribute(String catalogId, String attributeName); AttributeModel saveAttribute(AttributeModel attribute); void deleteAttribute(Long attributeId); } http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeServiceImpl.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeServiceImpl.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeServiceImpl.java index 27b4fc9..34865c5 100644 --- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeServiceImpl.java +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeServiceImpl.java @@ -44,6 +44,12 @@ public class AttributeServiceImpl extends AbstractPagingAndSortingService implem return attributeRepository.findAll(); } + @Override + public List<AttributeModel> getAttributes(String catalogId) { + return attributeRepository.findByCatalogId(catalogId); + } + + @Override public List<AttributeModel> getAttributes(int startPage, int itemsPerPage, String sortColumn, String direction) { Pageable pageable = createPageRequest(startPage, itemsPerPage, sortColumn, direction); Page<AttributeModel> page = attributeRepository.findAll(pageable); @@ -51,6 +57,18 @@ public class AttributeServiceImpl extends AbstractPagingAndSortingService implem } @Override + public List<AttributeModel> getAttributes(String catalogId, int startPage, int itemsPerPage, String sortColumn, String direction) { + Pageable pageable = createPageRequest(startPage, itemsPerPage, sortColumn, direction); + Page<AttributeModel> page = attributeRepository.findByCatalogId(catalogId, pageable); + return page.getContent(); + } + + @Override + public Optional<AttributeModel> getAttribute(String catalogId, String attributeName) { + return attributeRepository.findByCatalogIdAndName(catalogId, attributeName); + } + + @Override public Optional<AttributeModel> getAttribute(Long attributeId) { return attributeRepository.findOne(attributeId); } http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryService.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryService.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryService.java index 3532b7a..044ef8c 100644 --- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryService.java +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryService.java @@ -26,8 +26,12 @@ import org.apache.logging.log4j.catalog.jpa.model.CategoryModel; */ public interface CategoryService { List<CategoryModel> getCategories(int startPage, int itemsPerPage, String sortColumn, String direction); + List<CategoryModel> getCategories(String catalogId, int startPage, int itemsPerPage, String sortColumn, + String direction); List<CategoryModel> getCategories(); + List<CategoryModel> getCategories(String catalogId); Optional<CategoryModel> getCategory(Long categoryId); + Optional<CategoryModel> getCategory(String catalogId, String name); CategoryModel saveCategory(CategoryModel category); void deleteCategory(Long categoryId); } http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryServiceImpl.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryServiceImpl.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryServiceImpl.java index 3b7b6ef..0fc3050 100644 --- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryServiceImpl.java +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryServiceImpl.java @@ -45,6 +45,11 @@ public class CategoryServiceImpl extends AbstractPagingAndSortingService impleme } @Override + public List<CategoryModel> getCategories(String catalogId) { + return categoryRepository.findByCatalogId(catalogId); + } + + @Override public List<CategoryModel> getCategories(int startPage, int itemsPerPage, String sortColumn, String direction) { Pageable pageable = createPageRequest(startPage, itemsPerPage, sortColumn, direction); Page<CategoryModel> page = categoryRepository.findAll(pageable); @@ -52,11 +57,24 @@ public class CategoryServiceImpl extends AbstractPagingAndSortingService impleme } @Override + public List<CategoryModel> getCategories(String catalogId, int startPage, int itemsPerPage, String sortColumn, + String direction) { + Pageable pageable = createPageRequest(startPage, itemsPerPage, sortColumn, direction); + Page<CategoryModel> page = categoryRepository.findByCatalogId(catalogId, pageable); + return page.getContent(); + } + + @Override public Optional<CategoryModel> getCategory(Long categoryId) { return categoryRepository.findOne(categoryId); } @Override + public Optional<CategoryModel> getCategory(String catalogId, String name) { + return categoryRepository.findByCatalogIdAndName(catalogId, name); + } + + @Override public CategoryModel saveCategory(CategoryModel category) { return categoryRepository.save(category); } http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventService.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventService.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventService.java index 5382545..4c12f55 100644 --- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventService.java +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventService.java @@ -27,9 +27,12 @@ import org.apache.logging.log4j.catalog.jpa.model.EventModel; */ public interface EventService { List<EventModel> getEvents(int startPage, int itemsPerPage, String sortColumn, String direction); + List<EventModel> getEvents(String catalogId, int startPage, int itemsPerPage, String sortColumn, String direction); List<EventModel> getEvents(); + List<EventModel> getEvents(String catalogId); Map<String, EventModel> getEventMap(); Optional<EventModel> getEvent(Long eventId); + Optional<EventModel> getEvent(String catalogId, String eventName); EventModel saveEvent(EventModel event); void deleteEvent(Long eventId); } http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventServiceImpl.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventServiceImpl.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventServiceImpl.java index f7852b5..d612b28 100644 --- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventServiceImpl.java +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/EventServiceImpl.java @@ -47,6 +47,11 @@ public class EventServiceImpl extends AbstractPagingAndSortingService implements } @Override + public List<EventModel> getEvents(String catalogId) { + return eventRepository.findByCatalogId(catalogId); + } + + @Override public List<EventModel> getEvents(int startPage, int itemsPerPage, String sortColumn, String direction) { Pageable pageable = createPageRequest(startPage, itemsPerPage, sortColumn, direction); Page<EventModel> page = eventRepository.findAll(pageable); @@ -54,6 +59,14 @@ public class EventServiceImpl extends AbstractPagingAndSortingService implements } @Override + public List<EventModel> getEvents(String catalogId, int startPage, int itemsPerPage, String sortColumn, + String direction) { + Pageable pageable = createPageRequest(startPage, itemsPerPage, sortColumn, direction); + Page<EventModel> page = eventRepository.findByCatalogId(catalogId, pageable); + return page.getContent(); + } + + @Override public Map<String, EventModel> getEventMap() { List<EventModel> events = getEvents(); Map<String, EventModel> eventMap = new HashMap<>(events.size()); @@ -69,6 +82,11 @@ public class EventServiceImpl extends AbstractPagingAndSortingService implements } @Override + public Optional<EventModel> getEvent(String catalogId, String eventName) { + return eventRepository.findByCatalogIdAndName(catalogId, eventName); + } + + @Override public EventModel saveEvent(EventModel event) { return eventRepository.save(event); } http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductService.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductService.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductService.java index 4263090..0568e94 100644 --- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductService.java +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductService.java @@ -23,8 +23,12 @@ import java.util.Optional; public interface ProductService { List<ProductModel> getProducts(int startPage, int itemsPerPage, String sortColumn, String direction); + List<ProductModel> getProducts(String catalogId, int startPage, int itemsPerPage, String sortColumn, + String direction); List<ProductModel> getProducts(); + List<ProductModel> getProducts(String catalogId); Optional<ProductModel> getProduct(Long productId); + Optional<ProductModel> getProduct(String catalogId, String name); ProductModel saveProduct(ProductModel product); void deleteProduct(Long productId); } http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductServiceImpl.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductServiceImpl.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductServiceImpl.java index 92ed9a4..ca4d16f 100644 --- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductServiceImpl.java +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ProductServiceImpl.java @@ -45,6 +45,11 @@ public class ProductServiceImpl extends AbstractPagingAndSortingService implemen } @Override + public List<ProductModel> getProducts(String catalogId) { + return productRepository.findByCatalogId(catalogId); + } + + @Override public List<ProductModel> getProducts(int startPage, int itemsPerPage, String sortColumn, String direction) { Pageable pageable = createPageRequest(startPage, itemsPerPage, sortColumn, direction); Page<ProductModel> page = productRepository.findAll(pageable); @@ -52,10 +57,24 @@ public class ProductServiceImpl extends AbstractPagingAndSortingService implemen } @Override + public List<ProductModel> getProducts(String catalogId, int startPage, int itemsPerPage, String sortColumn, + String direction) { + Pageable pageable = createPageRequest(startPage, itemsPerPage, sortColumn, direction); + Page<ProductModel> page = productRepository.findByCatalogId(catalogId, pageable); + return page.getContent(); + } + + @Override public Optional<ProductModel> getProduct(Long productId) { return productRepository.findOne(productId); } + + @Override + public Optional<ProductModel> getProduct(String catalogId, String name) { + return productRepository.findByCatalogIdAndName(catalogId, name); + } + @Override public ProductModel saveProduct(ProductModel product) { return productRepository.save(product); http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/d5b3c5ba/log4j-catalog/log4j-catalog-war/pom.xml ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-war/pom.xml b/log4j-catalog/log4j-catalog-war/pom.xml index 152421c..70fb6d2 100644 --- a/log4j-catalog/log4j-catalog-war/pom.xml +++ b/log4j-catalog/log4j-catalog-war/pom.xml @@ -90,11 +90,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>javax</groupId> - <artifactId>javaee-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope>
