http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/ProductConverter.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/ProductConverter.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/ProductConverter.java new file mode 100644 index 0000000..98d8328 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/ProductConverter.java @@ -0,0 +1,56 @@ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.jpa.converter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.logging.log4j.catalog.api.Product; +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.EventService; +import org.modelmapper.AbstractConverter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ProductConverter extends AbstractConverter<Product, ProductModel> { + + @Autowired + private EventService eventService; + + public ProductModel convert(Product product) { + Map<String, EventModel> eventMap = eventService.getEventMap(); + ProductModel model = new ProductModel(); + model.setId(product.getId()); + model.setName(product.getName()); + model.setDescription(product.getDescription()); + model.setDisplayName(product.getDisplayName()); + model.setCatalogId(product.getCatalogId()); + List<EventModel> events = new ArrayList<>(product.getEvents().size()); + for (String name : product.getEvents()) { + EventModel event = eventMap.get(name); + if (event != null) { + events.add(event); + } else { + throw new IllegalArgumentException("Unknown event " + name + " for product " + product.getName()); + } + } + model.setEvents(events); + return model; + } +}
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/ProductModelConverter.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/ProductModelConverter.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/ProductModelConverter.java new file mode 100644 index 0000000..ead6875 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/ProductModelConverter.java @@ -0,0 +1,49 @@ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.jpa.converter; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.logging.log4j.catalog.api.Product; +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.EventService; +import org.modelmapper.AbstractConverter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ProductModelConverter extends AbstractConverter<ProductModel, Product> { + + @Autowired + private EventService eventService; + + public Product convert(ProductModel productModel) { + Product product = new Product(); + product.setId(productModel.getId()); + product.setName(productModel.getName()); + product.setDisplayName(productModel.getDisplayName()); + product.setDescription(productModel.getDescription()); + product.setCatalogId(productModel.getCatalogId()); + List<String> events = new ArrayList<>(productModel.getEvents().size()); + for (EventModel event : productModel.getEvents()) { + events.add(event.getName()); + } + product.setEvents(events); + return product; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/package-info.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/package-info.java new file mode 100644 index 0000000..5726218 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + */ +/** + * Catalog converters. + */ +package org.apache.logging.log4j.catalog.jpa.converter; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/AttributeRepository.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/AttributeRepository.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/AttributeRepository.java new file mode 100644 index 0000000..4c32382 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/AttributeRepository.java @@ -0,0 +1,22 @@ +/* + * 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.jpa.dao; + +import org.apache.logging.log4j.catalog.jpa.model.AttributeModel; + +public interface AttributeRepository extends PagingAndSortingRepository<AttributeModel, Long> { +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/BaseRepository.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/BaseRepository.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/BaseRepository.java new file mode 100644 index 0000000..5186af0 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/BaseRepository.java @@ -0,0 +1,40 @@ +/* + * 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.jpa.dao; + +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.repository.NoRepositoryBean; +import org.springframework.data.repository.Repository; + +import java.io.Serializable; +import java.util.List; +import java.util.Optional; + +@NoRepositoryBean +public interface BaseRepository <T, ID extends Serializable> extends Repository<T, ID>, JpaSpecificationExecutor<T> { + Optional<T> findOne(ID id); + List<T> findAll(); + List<T> findAll(Specification<T> spec); + @Modifying + T save(T persisted); + @Modifying + void delete(T deleted); + @Modifying + void deleteById(ID id); +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/CategoryRepository.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/CategoryRepository.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/CategoryRepository.java new file mode 100644 index 0000000..9aae6d5 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/CategoryRepository.java @@ -0,0 +1,25 @@ +/* + * 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.jpa.dao; + +import java.util.Optional; + +import org.apache.logging.log4j.catalog.jpa.model.CategoryModel; + +public interface CategoryRepository extends PagingAndSortingRepository<CategoryModel, Long> { + Optional<CategoryModel> findByName(String name); +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/ConstraintRepository.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/ConstraintRepository.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/ConstraintRepository.java new file mode 100644 index 0000000..bd65589 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/ConstraintRepository.java @@ -0,0 +1,23 @@ +/* + * 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.jpa.dao; + +import org.apache.logging.log4j.catalog.jpa.model.ConstraintModel; + +public interface ConstraintRepository extends BaseRepository<ConstraintModel, Long> { + +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/EventRepository.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/EventRepository.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/EventRepository.java new file mode 100644 index 0000000..b04da34 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/EventRepository.java @@ -0,0 +1,22 @@ +/* + * 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.jpa.dao; + +import org.apache.logging.log4j.catalog.jpa.model.EventModel; + +public interface EventRepository extends PagingAndSortingRepository<EventModel, Long> { +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/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 new file mode 100644 index 0000000..2cf4b5b --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/PagingAndSortingRepository.java @@ -0,0 +1,31 @@ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.jpa.dao; + +import java.io.Serializable; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.repository.NoRepositoryBean; + +@NoRepositoryBean +public interface PagingAndSortingRepository<T, ID extends Serializable> extends BaseRepository<T, ID> { + + Iterable<T> findAll(Sort sort); + + Page<T> findAll(Pageable pageable); +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/ProductRepository.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/ProductRepository.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/ProductRepository.java new file mode 100644 index 0000000..5f6011d --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/ProductRepository.java @@ -0,0 +1,22 @@ +/* + * 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.jpa.dao; + +import org.apache.logging.log4j.catalog.jpa.model.ProductModel; + +public interface ProductRepository extends PagingAndSortingRepository<ProductModel, Long> { +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/package-info.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/package-info.java new file mode 100644 index 0000000..9c17be9 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/dao/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + */ +/** + * Catalog data access objects. + */ +package org.apache.logging.log4j.catalog.jpa.dao; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/exception/InvalidEnvironmentException.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/exception/InvalidEnvironmentException.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/exception/InvalidEnvironmentException.java new file mode 100644 index 0000000..014d2ad --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/exception/InvalidEnvironmentException.java @@ -0,0 +1,41 @@ +/* + * 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.jpa.exception; + +/** + * + */ +public class InvalidEnvironmentException extends RuntimeException { + + private static final long serialVersionUID = 5430017753467095045L; + + public InvalidEnvironmentException() { + super(); + } + + public InvalidEnvironmentException(String msg) { + super(msg); + } + + public InvalidEnvironmentException(Throwable t) { + super(t); + } + + public InvalidEnvironmentException(String msg, Throwable t) { + super(msg, t); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/exception/InvalidSiteException.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/exception/InvalidSiteException.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/exception/InvalidSiteException.java new file mode 100644 index 0000000..9744ff1 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/exception/InvalidSiteException.java @@ -0,0 +1,41 @@ +/* + * 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.jpa.exception; + +/** + * + */ +public class InvalidSiteException extends RuntimeException { + + private static final long serialVersionUID = -705205114100982089L; + + public InvalidSiteException() { + super(); + } + + public InvalidSiteException(String msg) { + super(msg); + } + + public InvalidSiteException(Throwable t) { + super(t); + } + + public InvalidSiteException(String msg, Throwable t) { + super(msg, t); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/AttributeModel.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/AttributeModel.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/AttributeModel.java new file mode 100644 index 0000000..1fd5bf8 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/AttributeModel.java @@ -0,0 +1,323 @@ +/* + * 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.jpa.model; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.logging.log4j.catalog.api.DataType; +import org.apache.logging.log4j.catalog.jpa.converter.BooleanToStringConverter; +import org.apache.logging.log4j.catalog.jpa.converter.DataTypeConverter; + +import javax.persistence.CascadeType; +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.Convert; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +@Entity +@Table(name = "EVENT_ATTRIBUTE", + uniqueConstraints = { @UniqueConstraint(columnNames = { "NAME" })}) +public class AttributeModel implements Serializable { + private static final long serialVersionUID = -756109102178482698L; + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name = "ID", updatable = false, nullable = false) + private Long id; + @Column(name = "NAME") + private String name; + @Column(name = "DISPLAY_NAME") + private String displayName; + @Column(name = "DESCRIPTION") + private String description; + @Column(name = "CATALOG_ID") + private String catalogId; + @Column(name = "DATATYPE") + @Convert(converter=DataTypeConverter.class) + private DataType dataType; + @Column(name = "INDEXED") + @Convert(converter=BooleanToStringConverter.class) + private boolean indexed; + @Column(name = "SORTABLE") + @Convert(converter=BooleanToStringConverter.class) + private boolean sortable; + @Column(name = "REQUIRED") + @Convert(converter=BooleanToStringConverter.class) + private boolean required; + @Column(name = "REQUEST_CONTEXT") + @Convert(converter=BooleanToStringConverter.class) + private boolean requestContext; + @ElementCollection(fetch = FetchType.EAGER) + @CollectionTable(name = "attribute_examples", joinColumns = @JoinColumn(name = "attribute_id")) + @Column(name = "example") + private Set<String> examples = new HashSet<>(); + @ElementCollection(fetch = FetchType.EAGER) + @CollectionTable(name = "attribute_aliases", joinColumns = @JoinColumn(name = "attribute_id")) + @Column(name = "alias") + private Set<String> aliases = new HashSet<>(); + @OneToMany(fetch = FetchType.EAGER, mappedBy = "attribute", cascade = CascadeType.ALL) + private Set<ConstraintModel> constraints; + + public AttributeModel() { + catalogId = "DEFAULT"; + } + + + /** + * Returns the id of the AttributeDto. + * @return + */ + public Long getId() { + return id; + } + + /** + * Set the id of the AttributeDto. + * @param id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Returns the name of the AttributeDto. + */ + public String getName() { + return name; + } + + /** + * Set the name of the AttributeDto. + * @param name the name of the attribute. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns the name used when displaying the attribute. + * @return the display name of the attribute. + */ + public String getDisplayName() { + return displayName; + } + + /** + * Set the name to be displayed for this attribute. + * @param name the display name for the attribute. + */ + public void setDisplayName(String name) { + this.displayName = name; + } + + /** + * Returns the description of the attribute. + * @return the description of the attribute. + */ + public String getDescription() { + return description; + } + + /** + * Set the description of the attribute. + * @param description the description of the attribute. + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Returns the data type of this attribute. + * @return the data type of the attribute. + */ + public DataType getDataType() { + return dataType; + } + + /** + * Set the data type of the attribute. + * @param dataType the data type of the attribute. + */ + public void setDataType(DataType dataType) { + this.dataType = dataType; + } + + /** + * Identifies whether this attribute is an index. + * @return true if this attribute is an index, false otherwise. + */ + public boolean isIndexed() { + return indexed; + } + + /** + * Set whether this attribute is an index. + * @param indexed true if this attribute is an index, false otherwise. + */ + public void setIndexed(boolean indexed) { + this.indexed = indexed; + } + + /** + * Returns whether a sort may be performed on this attribute. + * @return true if a sort can be performed on this attribute, false otherwise. + */ + public boolean isSortable() { + return sortable; + } + + /** + * Set whether a sort may be performed on this attribute. + * @param sortable true if a sort may be performed on this attribute, false otherwise. + */ + public void setSortable(boolean sortable) { + this.sortable = sortable; + } + + /** + * Returns whether this attribute is required. + * @return true if this attribute is required, false otherwise. + */ + public boolean isRequired() { + return required; + } + + /** + * Set whether this attribute is required. + * @param required true if this attribute is required, false otherwise. + */ + public void setRequired(boolean required) { + this.required = required; + } + + /** + * Returns whether this attribute is part of the RequestContext. + * @return true if this attribute is part of the RequestContext, false otherwise. + */ + public boolean isRequestContext() { + return requestContext; + } + + /** + * Set whether this attribute is part of the RequestContext. + * @param isRequestContext true if this attribute is part of the RequestContext, false otherwise. + */ + public void setRequestContext(boolean isRequestContext) { + this.requestContext = isRequestContext; + } + + /** + * Returns the List of example Strings. + * @return the List of example Strings. + */ + public Set<String> getExamples() { + return examples; + } + + /** + * Sets the List of example Strings. + * @param examples the List of example Strings. + */ + public void setExamples(Set<String> examples) { + this.examples = examples; + } + + /** + * Returns the List of alias Strings. + * @return the List of alias Strings. + */ + public Set<String> getAliases() { + return aliases; + } + + /** + * Get the Catalog Id this attribute is associated with. + * @return the catalog id or null. + */ + public String getCatalogId() { + return catalogId; + } + + /** + * Set the catalog id this attribute is associated with. + * @param catalogId The catalog id or null. + */ + public void setCatalogId(String catalogId) { + this.catalogId = catalogId; + } + + /** + * Sets List of alias Strings. + * @param aliases The List of alias Strings. + */ + public void setAliases(Set<String> aliases) { + this.aliases = aliases; + } + + public Set<ConstraintModel> getConstraints() { + return constraints; + } + + public void setConstraints(Set<ConstraintModel> constraints) { + if (constraints == null) { + if (this.constraints == null) { + this.constraints = new HashSet<>(); + } + } else { + for (ConstraintModel constraint : constraints) { + if (constraint.getAttribute() != this) { + constraint.setAttribute(this); + } + } + this.constraints = constraints; + } + } + + /* + public Set<EventAttributeModel> getAttributes() { + return attributes; + } + + public void setAttributes(Set<EventAttributeModel> attributes) { + this.attributes = attributes; + } */ + + public int hashCode() { + return new HashCodeBuilder().append(name).toHashCode(); + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if (!(o instanceof AttributeModel)) return false; + + AttributeModel other = (AttributeModel)o; + return new EqualsBuilder().append(name, other.name).isEquals(); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/CategoryModel.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/CategoryModel.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/CategoryModel.java new file mode 100644 index 0000000..8c03be2 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/CategoryModel.java @@ -0,0 +1,168 @@ +/* + * 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.jpa.model; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; +import java.io.Serializable; +import java.util.List; + +/** + * A Catalog CategoryDto. + */ +@Entity +@Table(name = "CATALOG_CATEGORY", + uniqueConstraints = { @UniqueConstraint(columnNames = { "NAME" })}) +public class CategoryModel implements Serializable { + private static final long serialVersionUID = 5776108323599073407L; + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name = "ID") + private Long id; + @Column(name = "NAME") + private String name; + @Column(name = "DISPLAY_NAME") + private String displayName; + @Column(name = "DESCRIPTION") + private String description; + @Column(name = "CATALOG_ID") + private String catalogId; + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "category_events", joinColumns = { @JoinColumn(name = "category_id")}, + inverseJoinColumns = { @JoinColumn(name = "event_id")}) + private List<EventModel> events; + + public CategoryModel() { + catalogId = "DEFAULT"; + } + + /** + * Returns the id of the AttributeDto. + * @return + */ + public Long getId() { + return id; + } + + /** + * Set the id of the AttributeDto. + * @param id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Gets the value of the name property. + * + * @return possible object is + * {@link String } + */ + public String getName() { + return name; + } + + /** + * Sets the value of the name property. + * + * @param value allowed object is + * {@link String } + */ + public void setName(String value) { + this.name = value; + } + + /** + * The value used when displaying the category name. + * @return the display name. + */ + public String getDisplayName() { + return displayName; + } + + /** + * Sets the value to be used when displaying the name. + * @param dislpayName The display name. + */ + public void setDisplayName(String dislpayName) { + this.displayName = dislpayName; + } + + /** + * Gets the value of the description property. + * + * @return possible object is + * {@link String } + */ + public String getDescription() { + return description; + } + + /** + * Sets the value of the description property. + * + * @param value allowed object is + * {@link String } + */ + public void setDescription(String value) { + this.description = value; + } + + /** + * Get the Catalog Id this Category is associated with. + * @return the catalog id or null. + */ + public String getCatalogId() { + return catalogId; + } + + /** + * Set the catalog id this Category is associated with. + * @param catalogId The catalog id or null. + */ + public void setCatalogId(String catalogId) { + this.catalogId = catalogId; + } + + /** + * Return the List of EventDto objects. + * @return the List of Events or null. + */ + public List<EventModel> getEvents() { + return events; + } + + /** + * Sets the List of EventDto objects. + * @param events the List of Events. + */ + public void setEvents(List<EventModel> events) { + this.events = events; + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/ConstraintModel.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/ConstraintModel.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/ConstraintModel.java new file mode 100644 index 0000000..eb70da6 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/ConstraintModel.java @@ -0,0 +1,85 @@ +/* + * 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.jpa.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * A Catalog Attribute Constraint. + */ +@Entity +@Table(name = "ATTRIBUTE_CONSTRAINT") +public class ConstraintModel implements Serializable { + + private static final long serialVersionUID = 6836453963830996541L; + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name = "ID") + private Long id; + @ManyToOne + @JoinColumn(name = "ATTRIBUTE_ID") + private AttributeModel attribute; + @Column(name = "CONSTRAINT_TYPE") + private String constraintType; + @Column(name = "VALUE") + private String value; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getConstraintType() { + return constraintType; + } + + public void setConstraintType(String constraintType) { + this.constraintType = constraintType; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public AttributeModel getAttribute() { + return attribute; + } + + public void setAttribute(AttributeModel attribute) { + this.attribute = attribute; + if (attribute.getConstraints() != null && !attribute.getConstraints().contains(this)) { + attribute.getConstraints().add(this); + } + + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventAttributeModel.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventAttributeModel.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventAttributeModel.java new file mode 100644 index 0000000..5f01dcd --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventAttributeModel.java @@ -0,0 +1,119 @@ +/* + * 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.jpa.model; + +import javax.persistence.Column; +import javax.persistence.Convert; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import java.io.Serializable; + +import org.apache.logging.log4j.catalog.jpa.converter.BooleanToStringConverter; + +/** + * + */ +@Entity +@Table(name = "event_attributes") +public class EventAttributeModel implements Serializable { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name = "ID", updatable = false, nullable = false) + private Long id; + + @ManyToOne + @JoinColumn(name = "event_id", referencedColumnName = "id") + private EventModel event; + + @ManyToOne + @JoinColumn(name = "attribute_id", referencedColumnName = "id") + private AttributeModel attribute; + + @Column(name = "is_required") + @Convert(converter=BooleanToStringConverter.class) + private boolean isRequired; + + /** + * Return the identifier for this event. + * @return the identifier for this event. + */ + public Long getId() { + return id; + } + + /** + * Set the identifier for this event. + * @param id the identifier for this event. + */ + public void setId(Long id) { + this.id = id; + } + + public EventModel getEvent() { + return event; + } + + public void setEvent(EventModel event) { + this.event = event; + } + + public AttributeModel getAttribute() { + return attribute; + } + + public void setAttribute(AttributeModel attribute) { + this.attribute = attribute; + } + + public boolean isRequired() { + return isRequired; + } + + public void setRequired(boolean required) { + isRequired = required; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + EventAttributeModel that = (EventAttributeModel) o; + + if (!event.equals(that.event)) { + return false; + } + return attribute.equals(that.attribute); + } + + @Override + public int hashCode() { + int result = event == null ? 0 : event.hashCode(); + result = 31 * result + attribute.hashCode(); + return result; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventModel.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventModel.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventModel.java new file mode 100644 index 0000000..0781143 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventModel.java @@ -0,0 +1,232 @@ +/* + * 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.jpa.model; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +import javax.persistence.CascadeType; +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Entity +@Table(name = "CATALOG_EVENT", + uniqueConstraints = { @UniqueConstraint(columnNames = { "NAME" })}) +public class EventModel implements Serializable { + private static final long serialVersionUID = 1512172827909901054L; + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name = "ID", updatable = false, nullable = false) + private Long id; + @Column(name = "NAME") + private String name; + @Column(name = "DISPLAY_NAME") + private String displayName; + @Column(name = "DESCRIPTION") + private String description; + @Column(name = "CATALOG_ID") + private String catalogId; + @ElementCollection(fetch = FetchType.EAGER) + @CollectionTable(name = "event_aliases", joinColumns = @JoinColumn(name = "event_id")) + @Column(name = "alias") + private Set<String> aliases; + @OneToMany(fetch = FetchType.EAGER, mappedBy = "event", cascade = CascadeType.ALL, orphanRemoval = true) + private Set<EventAttributeModel> attributes = new HashSet<>(); + + public EventModel() { + catalogId = "DEFAULT"; + } + + /** + * Return the identifier for this event. + * @return the identifier for this event. + */ + public Long getId() { + return id; + } + + /** + * Set the identifier for this event. + * @param id the identifier for this event. + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Returns the name for this event. + * @return the name for this event. + */ + public String getName() { + return name; + } + + /** + * Set the name for this event. + * @param name the name for this event. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns the name to display for this event. + * @return the display name for this event. + */ + public String getDisplayName() { + return displayName; + } + + /** + * Set the display name for this event. + * @param name the name to display for this event. + */ + public void setDisplayName(String name) { + this.displayName = name; + } + + /** + * Return the description of the event. + * @return the event description. + */ + public String getDescription() { + return description; + } + + /** + * Set the event description. + * @param description The description of the event. + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Returns the List of alias Strings. + * @return the List of alias Strings. + */ + public Set<String> getAliases() { + return aliases; + } + + /** + * Sets the List of alias Strings. + * @param aliases the List of alias Strings. + */ + public void setAliases(Set<String> aliases) { + this.aliases = aliases; + } + + /** + * Get the Catalog Id this Event is associated with. + * @return the catalog id or null. + */ + public String getCatalogId() { + return catalogId; + } + + /** + * Set the catalog id this Event is associated with. + * @param catalogId The catalog id or null. + */ + public void setCatalogId(String catalogId) { + this.catalogId = catalogId; + } + + /** + * Returns the List of AttributeDto objects. + * @return the List of Attributes. + */ + public Set<EventAttributeModel> getAttributes() { + return attributes; + } + + public List<String> getAttributeNames() { + List<String> names = new ArrayList<>(attributes.size()); + for (EventAttributeModel model : attributes) { + names.add(model.getAttribute().getName()); + } + return names; + } + + public EventAttributeModel getAttribute(String name) { + for (EventAttributeModel model : attributes) { + if (name.equals(model.getAttribute().getName())) { + return model; + } + } + return null; + } + + public void addEventAttribute(EventAttributeModel attribute) { + this.attributes.add(attribute); + } + + /** + * Sets the List of Atribute objects. + * @param attributes The List of Attributes. + */ + public void setAttributes(Set<EventAttributeModel> attributes) { + this.attributes = attributes; + } + + public int hashCode() { + return new HashCodeBuilder().append(name).toHashCode(); + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if (!(o instanceof EventModel)) return false; + + EventModel other = (EventModel)o; + return new EqualsBuilder().append(name, other.name).isEquals(); + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{\"id\" : \"").append(id).append("\""); + sb.append(", \"name\" : \"").append(name).append("\", \"displayName\" : \"").append(displayName).append("\""); + sb.append(", \"description\" : ").append(description).append("\", \"attributes\" : ["); + boolean first = true; + for (EventAttributeModel attribute : attributes) { + if (!first) { + sb.append(", "); + } else { + first = false; + } + sb.append("{\"name\" : \"").append(attribute.getAttribute().getName()).append("\", \"required\" : ").append(attribute.isRequired()).append("}"); + } + sb.append("]}"); + return sb.toString(); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/ProductModel.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/ProductModel.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/ProductModel.java new file mode 100644 index 0000000..17e42cb --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/ProductModel.java @@ -0,0 +1,152 @@ +/* + * 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.jpa.model; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; +import java.io.Serializable; +import java.util.List; + +import org.apache.logging.log4j.catalog.api.Product; + +/** + * Definition of a ProductDto. + */ +@Entity +@Table(name = "CATALOG_PRODUCT", + uniqueConstraints = { @UniqueConstraint(columnNames = { "NAME" })}) +public class ProductModel implements Serializable { + private static final long serialVersionUID = -736368842796386523L; + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name = "ID") + private Long id; + @Column(name = "NAME") + private String name; + @Column(name = "DISPLAY_NAME") + private String displayName; + @Column(name = "DESCRIPTION") + private String description; + @Column(name = "CATALOG_ID") + private String catalogId; + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "PRODUCT_EVENTS", joinColumns = { @JoinColumn(name = "PRODUCT_ID")}, + inverseJoinColumns = { @JoinColumn(name = "EVENT_ID")}) + private List<EventModel> events; + + public ProductModel() { + catalogId = "DEFAULT"; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + /** + * Returns the name of the product. + * @return the name of the product. + */ + public String getName() { + return name; + } + + /** + * Set the name of the product. + * @param name the name of the product. + */ + public void setName(String name) { + this.name = name; + } + + /** + * The value used when displaying the category name. + * @return the display name. + */ + public String getDisplayName() { + return displayName; + } + + /** + * Sets the value to be used when displaying the name. + * @param dislpayName The display name. + */ + public void setDisplayName(String dislpayName) { + this.displayName = dislpayName; + } + /** + * Return the product description. + * @return the description of the product. + */ + public String getDescription() { + return description; + } + + /** + * Set the description of the product. + * @param description the description of the product. + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Get the Catalog Id this Product is associated with. + * @return the catalog id or null. + */ + public String getCatalogId() { + return catalogId; + } + + /** + * Set the catalog id this Product is associated with. + * @param catalogId The catalog id or null. + */ + public void setCatalogId(String catalogId) { + this.catalogId = catalogId; + } + + /** + * Returns the List of EventDto objects associated with this product. + * @return the List of Events. + */ + public List<EventModel> getEvents() { + return events; + } + + /** + * Sets the List of EventDto objects. + * @param events the List of Events. + */ + public void setEvents(List<EventModel> events) { + this.events = events; + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/package-info.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/package-info.java new file mode 100644 index 0000000..6905450 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + */ +/** + * Catalog model objects. + */ +package org.apache.logging.log4j.catalog.jpa.model; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/package-info.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/package-info.java new file mode 100644 index 0000000..edbf663 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + */ +/** + * Support storing the catalog using JPA. + */ +package org.apache.logging.log4j.catalog.jpa; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AbstractPagingAndSortingService.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AbstractPagingAndSortingService.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AbstractPagingAndSortingService.java new file mode 100644 index 0000000..d7de9d3 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AbstractPagingAndSortingService.java @@ -0,0 +1,44 @@ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.jpa.service; + +import java.util.Locale; + +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; + +public class AbstractPagingAndSortingService { + + protected Pageable createPageRequest(int startPage, int itemsPerPage, String sortColumn, String direction) { + PageRequest pageRequest; + if (sortColumn == null || sortColumn.length() == 0) { + pageRequest = new PageRequest(startPage, itemsPerPage); + } else { + Sort.Direction sortDirection; + if (direction == null) { + sortDirection = Sort.Direction.ASC; + } else { + sortDirection = Sort.Direction.fromStringOrNull(direction.toUpperCase(Locale.US)); + if (sortDirection == null) { + sortDirection = Sort.Direction.ASC; + } + } + pageRequest = new PageRequest(startPage, itemsPerPage, new Sort(sortDirection, sortColumn)); + } + return pageRequest; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/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 new file mode 100644 index 0000000..368153c --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeService.java @@ -0,0 +1,33 @@ +/* + * 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.jpa.service; + +import java.util.List; +import java.util.Optional; + +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(); + Optional<AttributeModel> getAttribute(Long attributeId); + AttributeModel saveAttribute(AttributeModel attribute); + void deleteAttribute(Long attributeId); +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/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 new file mode 100644 index 0000000..27b4fc9 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/AttributeServiceImpl.java @@ -0,0 +1,67 @@ +/* + * 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.jpa.service; + +import java.util.List; +import java.util.Optional; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.catalog.jpa.dao.AttributeRepository; +import org.apache.logging.log4j.catalog.jpa.model.AttributeModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Repository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Repository +@Transactional +public class AttributeServiceImpl extends AbstractPagingAndSortingService implements AttributeService { + private static final Logger LOGGER = LogManager.getLogger(); + + @Autowired + private AttributeRepository attributeRepository; + + @Override + public List<AttributeModel> getAttributes() { + return attributeRepository.findAll(); + } + + 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); + return page.getContent(); + } + + @Override + public Optional<AttributeModel> getAttribute(Long attributeId) { + return attributeRepository.findOne(attributeId); + } + + @Override + public AttributeModel saveAttribute(AttributeModel attribute) { + return attributeRepository.save(attribute); + } + + @Override + public void deleteAttribute(Long attributeId) { + attributeRepository.deleteById(attributeId); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CatalogServiceImpl.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CatalogServiceImpl.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CatalogServiceImpl.java new file mode 100644 index 0000000..7d53bc8 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CatalogServiceImpl.java @@ -0,0 +1,121 @@ +/* + * 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.jpa.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.logging.log4j.catalog.api.Attribute; +import org.apache.logging.log4j.catalog.api.CatalogData; +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.plugins.ConstraintPlugins; +import org.apache.logging.log4j.catalog.api.service.CatalogService; +import org.apache.logging.log4j.catalog.jpa.converter.AttributeModelConverter; +import org.apache.logging.log4j.catalog.jpa.converter.CategoryModelConverter; +import org.apache.logging.log4j.catalog.jpa.converter.EventModelConverter; +import org.apache.logging.log4j.catalog.jpa.converter.ProductModelConverter; +import org.apache.logging.log4j.catalog.jpa.dao.AttributeRepository; +import org.apache.logging.log4j.catalog.jpa.dao.CategoryRepository; +import org.apache.logging.log4j.catalog.jpa.dao.EventRepository; +import org.apache.logging.log4j.catalog.jpa.dao.ProductRepository; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Repository +@Transactional(readOnly = false) +public class CatalogServiceImpl implements CatalogService { + + private static final ConstraintPlugins constraintPlugins = ConstraintPlugins.getInstance(); + + @Autowired + private AttributeRepository attributeRepository; + @Autowired + private EventRepository eventRepository; + @Autowired + private CategoryRepository categoryRepository; + @Autowired + private ProductRepository productRepository; + @Autowired + private AttributeModelConverter attributeModelConverter; + @Autowired + private EventModelConverter eventModelConverter; + @Autowired + private CategoryModelConverter categoryModelConverter; + @Autowired + private ProductModelConverter productModelConverter; + + + public CatalogData getCatalogData() { + CatalogData data = new CatalogData(); + + List<AttributeModel> modelAttributes = attributeRepository.findAll(); + List<org.apache.logging.log4j.catalog.api.Attribute> attributes = new ArrayList<>(modelAttributes.size()); + for (AttributeModel modelAttribute : modelAttributes) { + Attribute attribute = attributeModelConverter.convert(modelAttribute); + attributes.add(attribute); + } + data.setAttributes(attributes); + + List<EventModel> modelEvents = eventRepository.findAll(); + List<org.apache.logging.log4j.catalog.api.Event> events = new ArrayList<>(modelEvents.size()); + for (EventModel modelEvent : modelEvents) { + Event event = eventModelConverter.convert(modelEvent); + events.add(event); + } + data.setEvents(events); + + List<CategoryModel> modelCategories = categoryRepository.findAll(); + List<org.apache.logging.log4j.catalog.api.Category> categories = new ArrayList<>(modelCategories.size()); + for (CategoryModel modelCategory : modelCategories) { + Category category = categoryModelConverter.convert(modelCategory); + categories.add(category); + } + data.setCategories(categories); + + List<ProductModel> modelProducts = productRepository.findAll(); + List<Product> products = new ArrayList<>(modelProducts.size()); + for (ProductModel modelProduct : modelProducts) { + Product product = productModelConverter.convert(modelProduct); + products.add(product); + } + data.setProducts(products); + + return data; + } + + public List<CategoryModel> getCategories() { + return categoryRepository.findAll(); + } + + public Optional<CategoryModel> getCategory(String name) { + return categoryRepository.findByName(name); + } + + public Optional<CategoryModel> getCategory(long id) { + return categoryRepository.findOne(id); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/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 new file mode 100644 index 0000000..3532b7a --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryService.java @@ -0,0 +1,33 @@ +/* + * 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.jpa.service; + +import java.util.List; +import java.util.Optional; + +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(); + Optional<CategoryModel> getCategory(Long categoryId); + CategoryModel saveCategory(CategoryModel category); + void deleteCategory(Long categoryId); +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/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 new file mode 100644 index 0000000..3b7b6ef --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/CategoryServiceImpl.java @@ -0,0 +1,68 @@ +/* + * 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.jpa.service; + +import java.util.List; +import java.util.Optional; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.catalog.jpa.dao.CategoryRepository; +import org.apache.logging.log4j.catalog.jpa.model.CategoryModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Repository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Repository +@Transactional +public class CategoryServiceImpl extends AbstractPagingAndSortingService implements CategoryService { + private static final Logger LOGGER = LogManager.getLogger(); + + @Autowired + private CategoryRepository categoryRepository; + + @Override + public List<CategoryModel> getCategories() { + return categoryRepository.findAll(); + } + + @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); + return page.getContent(); + } + + @Override + public Optional<CategoryModel> getCategory(Long categoryId) { + return categoryRepository.findOne(categoryId); + } + + @Override + public CategoryModel saveCategory(CategoryModel category) { + return categoryRepository.save(category); + } + + @Override + public void deleteCategory(Long categoryId) { + categoryRepository.deleteById(categoryId); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ConfigurationService.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ConfigurationService.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ConfigurationService.java new file mode 100644 index 0000000..ac21e70 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ConfigurationService.java @@ -0,0 +1,31 @@ +/* + * 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.jpa.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class ConfigurationService { + + @Value("${catalogServiceAuthToken:cbade18f-437a-412c-b0c5-9e246ee23ca6}") + private String catalogServiceAuthToken; + + public String getCatalogServiceAuthToken() { + return catalogServiceAuthToken; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/f0884aeb/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ConstraintService.java ---------------------------------------------------------------------- diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ConstraintService.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ConstraintService.java new file mode 100644 index 0000000..40af9c4 --- /dev/null +++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/service/ConstraintService.java @@ -0,0 +1,33 @@ +/* + * 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.jpa.service; + +import java.util.List; +import java.util.Optional; +import java.util.Set; +import org.apache.logging.log4j.catalog.jpa.model.ConstraintModel; + +/** + * + */ +public interface ConstraintService { + Set<String> getConstraintTypes(); + List<ConstraintModel> getConstraints(); + Optional<ConstraintModel> getConstraint(Long constraintId); + ConstraintModel saveConstraint(ConstraintModel constraint); + void deleteConstraint(Long constraintId); +}
