diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f35a1af --- /dev/null +++ b/.gitignore @@ -0,0 +1,235 @@ +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +### Gradle Patch ### +**/build/ + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +.idea/sonarlint + + +### Intellij+iml ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+iml Patch ### +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +.idea/sonarlint diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..1fed347 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..140f55e --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + h2.unified + true + org.h2.Driver + jdbc:h2:file:~/test;MODE=Mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa35c41 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml new file mode 100644 index 0000000..d08f400 --- /dev/null +++ b/.idea/jpa-buddy.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..8cf6a91 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..133cc64 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 FacilityConneX + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/common/pom.xml b/common/pom.xml new file mode 100644 index 0000000..f70799e --- /dev/null +++ b/common/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + orm-factory-common + Framework-Orm-Factory-common + jar + + + com.ossez.framework + orm-factory-parent + 0.0.1-SNAPSHOT + + + + + com.google.code.gson + gson + 2.8.6 + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + junit + junit + RELEASE + test + + + + + + 3.8.1 + + \ No newline at end of file diff --git a/common/src/main/java/com/ossez/framework/common/Constants.java b/common/src/main/java/com/ossez/framework/common/Constants.java new file mode 100644 index 0000000..4c344d4 --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/Constants.java @@ -0,0 +1,10 @@ +package com.ossez.framework.common; + +/** + * Constants for PRJ + * + * @author YuCheng Hu + */ +public class Constants { + public static final String PATH_DATA_EXCHANGE = "/home/yhu/ossez/dataExchange/"; +} diff --git a/common/src/main/java/com/ossez/framework/common/DataObject.java b/common/src/main/java/com/ossez/framework/common/DataObject.java new file mode 100644 index 0000000..141a5bd --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/DataObject.java @@ -0,0 +1,116 @@ +package com.ossez.framework.common; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.hibernate.search.annotations.DateBridge; +import org.hibernate.search.annotations.DocumentId; +import org.hibernate.search.annotations.Resolution; + +import javax.persistence.*; +import java.util.Date; +import java.util.Objects; + +/** + * DataObject + * + * @author YuCheng Hu + */ +@MappedSuperclass +public abstract class DataObject { + public abstract interface Save { + + } + + public abstract interface Update { + + } + + public static final String ID_PROPERTY_NAME = "id"; + public static final String CREATE_DATE_PROPERTY_NAME = "createDate"; + public static final String MODIFY_DATE_PROPERTY_NAME = "modifyDate"; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id = 0; + private String uuid; + private Date dateC; + private Date dateM; + + @JsonProperty + @DocumentId + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + /** + * @return + */ + @JsonProperty + @DateBridge(resolution = Resolution.SECOND) + @Column(nullable = false, updatable = false) + public Date getCreateDate() { + return this.dateC; + } + + /** + * @param createDate + */ + public void setCreateDate(Date createDate) { + this.dateC = createDate; + } + + + /** + * @return + */ + @JsonProperty + @DateBridge(resolution = Resolution.SECOND) + @Column(nullable = false) + public Date getDateC() { + return dateC; + } + + public void setDateC(Date dateC) { + this.dateC = dateC; + } + + /** + * @return + */ + @JsonProperty + @DateBridge(resolution = Resolution.SECOND) + @Column(nullable = false) + public Date getDateM() { + return dateM; + } + + public void setDateM(Date dateM) { + this.dateM = dateM; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DataObject that = (DataObject) o; + return id == that.id; + } + + @Override + public int hashCode() { + return Objects.hash(id); + } +} diff --git a/common/src/main/java/com/ossez/framework/common/dao/DeleteEventListener.java b/common/src/main/java/com/ossez/framework/common/dao/DeleteEventListener.java new file mode 100644 index 0000000..4efed27 --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/dao/DeleteEventListener.java @@ -0,0 +1,28 @@ +package com.ossez.framework.common.dao; + +import org.hibernate.event.internal.DefaultDeleteEventListener; +import org.hibernate.event.spi.EventSource; +import org.hibernate.persister.entity.EntityPersister; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Delete Event Listener + * + * @author YuCheng Hu + */ +public class DeleteEventListener extends DefaultDeleteEventListener { + private static Logger logger = LoggerFactory.getLogger(DeleteEventListener.class); + + /** + * Transient Entity + */ + protected void deleteTransientEntity(EventSource session, Object entity, boolean cascadeDeleteEnabled, EntityPersister persister, + Set transientEntities) { + super.deleteTransientEntity(session, entity, cascadeDeleteEnabled, persister, + transientEntities == null ? new HashSet() : transientEntities); + } +} diff --git a/common/src/main/java/com/ossez/framework/common/dao/Factory.java b/common/src/main/java/com/ossez/framework/common/dao/Factory.java new file mode 100644 index 0000000..3469114 --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/dao/Factory.java @@ -0,0 +1,302 @@ +package com.ossez.framework.common.dao; + + +import com.ossez.framework.common.DataObject; +import org.hibernate.Criteria; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.search.FullTextSession; +import org.hibernate.search.Search; +import org.hibernate.service.ServiceRegistry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; + +/** + * Factor for DAO + * + * @author YuCheng Hu + */ +public class Factory { + private static Logger logger = LoggerFactory.getLogger(Factory.class); + + private static SessionFactory sessionFactory; + private static ServiceRegistry serviceRegistry; + + private static int indexBatchSize = 100; + + // blocks the commit function from being called - this is useful for unit testing. + private static boolean noCommit = false; + + // executes a rollback instead of a commit when commit is called - this is useful for unit testing. + private static boolean autoRollback = false; + + // prevents the connection from being closed. This is useful for unit testing. + private static boolean noClose = false; + + /** + * Get Hibernate connection Session + * + * @return + */ + public static Session getSession() { + return Factory.getFactory().getCurrentSession(); + } + + /** + * Get session connection Get + * + * @return + */ + public static SessionFactory getFactory() { + if (Factory.sessionFactory == null) + Factory.sessionFactory = Factory.initSession(); + + return Factory.sessionFactory; + } + + /** + * Get SessionFactory + * + * @return + */ + public static SessionFactory initSession() { + Configuration configuration = new Configuration(); + configuration.configure(); + + serviceRegistry = new StandardServiceRegistryBuilder().configure().build(); + Metadata metadata = new MetadataSources(serviceRegistry).getMetadataBuilder().build(); + + sessionFactory = metadata.getSessionFactoryBuilder().build(); + return sessionFactory; + } + + /** + * Begin DataBase Transaction + */ + public static void beginTransaction() { + + if (!(Factory.getSession().getTransaction() != null && Factory.getSession().getTransaction().isActive())) { + Factory.getSession().getTransaction().begin(); + } else { + + } + } + + public static void commitTransaction() { + if (isAutoRollback()) { + Factory.rollbackTransaction(); + return; + } + if (Factory.getSession().getTransaction() != null && Factory.getSession().getTransaction().isActive()) { + if (!noCommit) + Factory.getSession().getTransaction().commit(); + } + } + + public static void rollbackTransaction() { + if (Factory.getSession().getTransaction() != null && Factory.getSession().getTransaction().isActive()) + Factory.getSession().getTransaction().rollback(); + } + + /** + * Gets an object of type T from Hibernate. + * + * @param + * @param classEntity + * @param id + * @return + */ + @SuppressWarnings("unchecked") + public static T get(Class classEntity, int id) { + Object object = Factory.getSession().get(classEntity, id); + + if (object == null) + return null; + + return (T) object; + } + + /** + * Saves the specified object to the database. + * + * @param object + */ + public static void save(DataObject object) { + if (object == null) + throw new NullPointerException("Object supplied is null"); + + if (object.getId() > 0) + Factory.getSession().saveOrUpdate(object); + else + Factory.getSession().save(object); + } + + /** + * Deletes the specified object. + * + * @param object + */ + public static void delete(DataObject object) { + Factory.getSession().delete(object); + } + + /** + * Creates an hibernate criteria object which is used to query against objects. + * + * @param classArg + * @return + */ + public static Criteria createCriteria(Class classArg) { + return Factory.getSession().createCriteria(classArg); + } + + /** + * Creates an hibernate criteria object with the specified alias. + * + * @param classArg + * @param alias + * @param + * @return + */ + public static Criteria createCriteria(Class classArg, String alias) { + return Factory.getSession().createCriteria(classArg, alias); + } + + /** + * Serializes an object into a byte array. + * + * @param object + * @return + */ + public static byte[] serialize(Object object) throws IOException { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + + try { + ObjectOutputStream serializer = new ObjectOutputStream(stream); + serializer.writeObject(object); + serializer.close(); + } catch (IOException ex) { + Factory.handleException(ex); + } + + byte[] result = stream.toByteArray(); + stream.close(); + return result; + } + + private static void handleException(IOException ex) { + // TODO Auto-generated method stub + + } + + /** + * Merges the specified instance. + * + * @param obj + */ + public static void merge(DataObject obj) { + Factory.getSession().merge(obj); + } + + /** + * Refreshes the specified instance. + * + * @param obj + */ + public static void refresh(DataObject obj) { + Factory.getSession().refresh(obj); + } + + /** + * Saves or updates the object. + * + * @param obj + */ + public static void saveOrUpdate(DataObject obj) { + Factory.getSession().saveOrUpdate(obj); + } + + /** + * Evicts the specified object from the session. + * + * @param obj + */ + public static void evict(DataObject obj) { + Factory.getSession().evict(obj); + } + + + /** + * Creates a hibernate query. + * + * @param query + * @return + */ + public static Query createQuery(String query) { + return Factory.getSession().createQuery(query); + } + + public static FullTextSession getFullTextSession() { + return Search.getFullTextSession(Factory.getSession()); + } + + /** + * Closes the session factory. Should only be called when an application is closing. + */ + public static void close() { + if (!isNoClose()) + Factory.getFactory().close(); + } + + + /** + * @param noCommit the noCommit to set + */ + public static void setNoCommit(boolean noCommit) { + Factory.noCommit = noCommit; + } + + /** + * @return the noCommit + */ + public static boolean isNoCommit() { + return noCommit; + } + + /** + * @param autoRollback the autoRollback to set + */ + public static void setAutoRollback(boolean autoRollback) { + Factory.autoRollback = autoRollback; + } + + /** + * @return the autoRollback + */ + public static boolean isAutoRollback() { + return autoRollback; + } + + /** + * @param noClose the noClose to set + */ + public static void setNoClose(boolean noClose) { + Factory.noClose = noClose; + } + + /** + * @return the noClose + */ + public static boolean isNoClose() { + return noClose; + } +} diff --git a/common/src/main/java/com/ossez/framework/common/dao/factories/CarFactory.java b/common/src/main/java/com/ossez/framework/common/dao/factories/CarFactory.java new file mode 100644 index 0000000..f843f14 --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/dao/factories/CarFactory.java @@ -0,0 +1,98 @@ +package com.ossez.framework.common.dao.factories; + + +import com.ossez.framework.common.dao.Factory; +import com.ossez.framework.common.models.CarType; +import com.ossez.framework.common.models.orm.CarInventory; +import com.ossez.framework.common.models.orm.CarReservation; +import com.ossez.framework.common.models.request.ReservationRequest; +import org.apache.commons.lang3.ObjectUtils; +import org.hibernate.Criteria; +import org.hibernate.criterion.Restrictions; +import org.joda.time.DateTime; +import org.joda.time.Instant; +import org.joda.time.LocalDateTime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.UUID; + +/** + * CarFactory to process database query + * + * @author YuCheng Hu + */ +public class CarFactory { + private final static Logger logger = LoggerFactory.getLogger(CarFactory.class); + + /** + * Search ReportManufacturer by ID + * + * @param id + * @return + */ + public static CarInventory getCarInventoryById(Long id) { + logger.debug("Search Database to find ReportManufacturer by ID"); + + Object obj = Factory.getSession().get(CarInventory.class, id); + + if (ObjectUtils.allNotNull(obj)) + return (CarInventory) obj; + else + return null; + } + + /** + * Search CarInventory by CarType + * + * @param carType + * @return + */ + public static List getCarInventory(CarType carType) { + logger.debug("Search Database to find ReportManufacturer by ID"); + + Criteria cr = Factory.createCriteria(CarInventory.class); + cr.add(Restrictions.eq("carType", carType)); + cr.add(Restrictions.isNull("confirmationNumber")); + + List results = cr.list(); + + return results; + } + + /** + * Search CarInventory by CarType + * + * @param reservationRequest + * @param carInventory + * @return + */ + public static CarReservation createReservation(ReservationRequest reservationRequest, CarInventory carInventory) { + logger.debug("Search Database to find ReportManufacturer by ID"); + + DateTime dateStart = new DateTime(reservationRequest.getDateReservationStart()); + + CarReservation carReservation = new CarReservation(); + carReservation.setCarInventoryId(carInventory.getId()); + carReservation.setDateReservationsStart(dateStart.toDate()); + carReservation.setDateReservationsStart(dateStart.plusDays(reservationRequest.getDurationReservation()).toDate()); + carReservation.setConfirmationNumber(UUID.randomUUID().toString()); + + Factory.save(carReservation); + + return carReservation; + } + + /** + * @param carInventory + * @return + */ + public static CarInventory saveCarInventory(CarInventory carInventory) { + logger.debug("Save CarInventory"); + + Factory.save(carInventory); + return carInventory; + } + +} diff --git a/common/src/main/java/com/ossez/framework/common/models/CarType.java b/common/src/main/java/com/ossez/framework/common/models/CarType.java new file mode 100644 index 0000000..f52af8e --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/models/CarType.java @@ -0,0 +1,11 @@ +package com.ossez.framework.common.models; + +/** + * + */ +public enum CarType { + SEDAN, + SUV, + VAN +} + diff --git a/common/src/main/java/com/ossez/framework/common/models/orm/CarInventory.java b/common/src/main/java/com/ossez/framework/common/models/orm/CarInventory.java new file mode 100644 index 0000000..486d455 --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/models/orm/CarInventory.java @@ -0,0 +1,67 @@ +package com.ossez.framework.common.models.orm; + +import com.ossez.framework.common.DataObject; +import com.ossez.framework.common.models.CarType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.*; +import java.io.Serializable; + + +/** + * + */ +@Entity +@Table(catalog = "CRD", name = "Car_Inventory") +public class CarInventory extends DataObject implements Serializable { + private static final long serialVersionUID = 5530454436970805656L; + + private static Logger logger = LoggerFactory.getLogger(CarInventory.class); + + @Column(name = "CAR_NAME") + private String carName; + + @Column(name = "CAR_TYPE") + @Enumerated(EnumType.ORDINAL) + private CarType carType; + + @Column(name = "CONFIRMATION_NUMBER") + private String confirmationNumber; + + /** + * Constructor + */ + public CarInventory() { + + } + + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public String getCarName() { + return carName; + } + + public void setCarName(String carName) { + this.carName = carName; + } + + public CarType getCarType() { + return carType; + } + + public void setCarType(CarType carType) { + this.carType = carType; + } + + + public String getConfirmationNumber() { + return confirmationNumber; + } + + public void setConfirmationNumber(String confirmationNumber) { + this.confirmationNumber = confirmationNumber; + } +} diff --git a/common/src/main/java/com/ossez/framework/common/models/orm/CarReservation.java b/common/src/main/java/com/ossez/framework/common/models/orm/CarReservation.java new file mode 100644 index 0000000..c10aec8 --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/models/orm/CarReservation.java @@ -0,0 +1,93 @@ +package com.ossez.framework.common.models.orm; + +import com.ossez.framework.common.DataObject; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; +import java.io.Serializable; +import java.util.Date; +import java.util.UUID; + +/** + * ORM For Table: CARS + */ +@Entity +@Table(catalog = "CRD", name = "Car_Reservation") +public class CarReservation extends DataObject implements Serializable { + + @Column(name = "CAR_INVENTORY_ID") + private Long carInventoryId; + + @Column(name = "CONFIRMATION_NUMBER") + private String confirmationNumber; + + @Column(name = "DATE_RESERVATION_START") + private Date dateReservationsStart; + + @Column(name = "DATE_RESERVATION_END") + private Date dateReservationEnd; + + @Column(name = "DATE_ACTUAL_START") + private Date dateActualStart; + + @Column(name = "DATE_ACTUAL_END") + private Date dateActualEnd; + + /** + * Constructor + */ + public CarReservation() { + this.setDateC(new Date()); + this.setDateM(new Date()); + this.setUuid(UUID.randomUUID().toString()); + } + + public Long getCarInventoryId() { + return carInventoryId; + } + + public void setCarInventoryId(Long carInventoryId) { + this.carInventoryId = carInventoryId; + } + + public String getConfirmationNumber() { + return confirmationNumber; + } + + public void setConfirmationNumber(String confirmationNumber) { + this.confirmationNumber = confirmationNumber; + } + + public Date getDateReservationsStart() { + return dateReservationsStart; + } + + public void setDateReservationsStart(Date dateReservationsStart) { + this.dateReservationsStart = dateReservationsStart; + } + + public Date getDateReservationEnd() { + return dateReservationEnd; + } + + public void setDateReservationEnd(Date dateReservationEnd) { + this.dateReservationEnd = dateReservationEnd; + } + + public Date getDateActualStart() { + return dateActualStart; + } + + public void setDateActualStart(Date dateActualStart) { + this.dateActualStart = dateActualStart; + } + + public Date getDateActualEnd() { + return dateActualEnd; + } + + public void setDateActualEnd(Date dateActualEnd) { + this.dateActualEnd = dateActualEnd; + } +} diff --git a/common/src/main/java/com/ossez/framework/common/models/request/ReservationRequest.java b/common/src/main/java/com/ossez/framework/common/models/request/ReservationRequest.java new file mode 100644 index 0000000..c0b5fe7 --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/models/request/ReservationRequest.java @@ -0,0 +1,50 @@ +package com.ossez.framework.common.models.request; + +import com.ossez.framework.common.models.CarType; + +import java.io.Serializable; +import java.util.Date; + + +/** + * SearchRequest Object, UI can send search String and related pagination + * + * @author YuCheng Hu + */ +public class ReservationRequest implements Serializable { + private static final long serialVersionUID = 6474765081240948885L; + + + private Date dateReservationStart; + private Integer durationReservation; + private CarType carType; + + + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public Date getDateReservationStart() { + return dateReservationStart; + } + + public void setDateReservationStart(Date dateReservationStart) { + this.dateReservationStart = dateReservationStart; + } + + public Integer getDurationReservation() { + return durationReservation; + } + + public void setDurationReservation(Integer durationReservation) { + this.durationReservation = durationReservation; + } + + public CarType getCarType() { + return carType; + } + + public void setCarType(CarType carType) { + this.carType = carType; + } +} diff --git a/common/src/main/java/com/ossez/framework/common/models/response/MyFileResponse.java b/common/src/main/java/com/ossez/framework/common/models/response/MyFileResponse.java new file mode 100644 index 0000000..77b2a06 --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/models/response/MyFileResponse.java @@ -0,0 +1,130 @@ +package com.ossez.framework.common.models.response; + +import java.io.Serializable; + +/** + * MyFileResponse for API my file response + * + * @author YuCheng Hu + */ +public class MyFileResponse implements Serializable { + private static final long serialVersionUID = -5103349220463423614L; + + private Long id; + private String azureInputFileUUID; + private String azureInputFileETag; + private String azureOutputFileUUID; + private String azureOutputFileETag; + private String customerName; + private String inputFileName; + private Integer fileCountRow; + private Integer fileCountAliasMatch; + private Integer fileCountDirectMatch; + private Integer fileCountNoMatch; + private String dateCreated; + private String uuid; + + public String getAzureInputFileUUID() { + return azureInputFileUUID; + } + + public void setAzureInputFileUUID(String azureInputFileUUID) { + this.azureInputFileUUID = azureInputFileUUID; + } + + public String getAzureInputFileETag() { + return azureInputFileETag; + } + + public void setAzureInputFileETag(String azureInputFileETag) { + this.azureInputFileETag = azureInputFileETag; + } + + public String getAzureOutputFileUUID() { + return azureOutputFileUUID; + } + + public void setAzureOutputFileUUID(String azureOutputFileUUID) { + this.azureOutputFileUUID = azureOutputFileUUID; + } + + public String getAzureOutputFileETag() { + return azureOutputFileETag; + } + + public void setAzureOutputFileETag(String azureOutputFileETag) { + this.azureOutputFileETag = azureOutputFileETag; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getInputFileName() { + return inputFileName; + } + + public void setInputFileName(String inputFileName) { + this.inputFileName = inputFileName; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getFileCountRow() { + return fileCountRow; + } + + public void setFileCountRow(Integer fileCountRow) { + this.fileCountRow = fileCountRow; + } + + public Integer getFileCountAliasMatch() { + return fileCountAliasMatch; + } + + public void setFileCountAliasMatch(Integer fileCountAliasMatch) { + this.fileCountAliasMatch = fileCountAliasMatch; + } + + public Integer getFileCountDirectMatch() { + return fileCountDirectMatch; + } + + public void setFileCountDirectMatch(Integer fileCountDirectMatch) { + this.fileCountDirectMatch = fileCountDirectMatch; + } + + public Integer getFileCountNoMatch() { + return fileCountNoMatch; + } + + public void setFileCountNoMatch(Integer fileCountNoMatch) { + this.fileCountNoMatch = fileCountNoMatch; + } + + public String getDateCreated() { + return dateCreated; + } + + public void setDateCreated(String dateCreated) { + this.dateCreated = dateCreated; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } +} diff --git a/common/src/main/java/com/ossez/framework/common/models/response/SearchResponse.java b/common/src/main/java/com/ossez/framework/common/models/response/SearchResponse.java new file mode 100644 index 0000000..a6a7074 --- /dev/null +++ b/common/src/main/java/com/ossez/framework/common/models/response/SearchResponse.java @@ -0,0 +1,37 @@ +package com.ossez.framework.common.models.response; + +import java.io.Serializable; +import java.util.Date; + +/** + * SearchResponse from Remote Source + * + * @author YuCheng Hu + */ +public class SearchResponse implements Serializable { + private static final long serialVersionUID = -2014480627591149391L; + + + private String uuid; + private Date currentDate; + + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public Date getCurrentDate() { + return currentDate; + } + + public void setCurrentDate(Date currentDate) { + this.currentDate = currentDate; + } +} diff --git a/common/src/main/resources/ehcache.xml b/common/src/main/resources/ehcache.xml new file mode 100644 index 0000000..afb0017 --- /dev/null +++ b/common/src/main/resources/ehcache.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/common/src/main/resources/hibernate.cfg.xml b/common/src/main/resources/hibernate.cfg.xml new file mode 100644 index 0000000..e6e1520 --- /dev/null +++ b/common/src/main/resources/hibernate.cfg.xml @@ -0,0 +1,36 @@ + + + + + 20 + true + 20 + thread + + + com.zaxxer.hikari.hibernate.HikariConnectionProvider + + HikariPool-Azure + 5 + 10 + 30000 + SELECT 1 + + + + true + org.hibernate.cache.ehcache.EhCacheRegionFactory + + + filesystem + /var/lucene/indexes/5 + + + + + + + + + diff --git a/common/src/main/resources/hibernate.properties b/common/src/main/resources/hibernate.properties new file mode 100644 index 0000000..8081657 --- /dev/null +++ b/common/src/main/resources/hibernate.properties @@ -0,0 +1,5 @@ +hibernate.connection.driver_class = org.h2.Driver +hibernate.dialect = org.hibernate.dialect.H2Dialect +hibernate.connection.url=jdbc:h2:mem:test;MODE=Mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE +hibernate.connection.username=sa +hibernate.connection.password= diff --git a/common/src/main/resources/log4j.xml b/common/src/main/resources/log4j.xml new file mode 100644 index 0000000..4739d89 --- /dev/null +++ b/common/src/main/resources/log4j.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/resources/log4j2.xml b/common/src/main/resources/log4j2.xml new file mode 100644 index 0000000..4739d89 --- /dev/null +++ b/common/src/main/resources/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/resources/logback.xml b/common/src/main/resources/logback.xml new file mode 100644 index 0000000..11e3a94 --- /dev/null +++ b/common/src/main/resources/logback.xml @@ -0,0 +1,15 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + diff --git a/common/src/test/java/com/ossez/framework/common/tests/dao/FirstTest.java b/common/src/test/java/com/ossez/framework/common/tests/dao/FirstTest.java new file mode 100644 index 0000000..789985d --- /dev/null +++ b/common/src/test/java/com/ossez/framework/common/tests/dao/FirstTest.java @@ -0,0 +1,22 @@ +package com.ossez.framework.common.tests.dao; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test Logger and function + * + * @author YuCheng Hu + */ +public class FirstTest { + private static Logger logger = LoggerFactory.getLogger(FirstTest.class); + + /** + * Check test function + */ + @Test + public void testString() { + logger.debug("TEST String"); + } +} diff --git a/common/src/test/java/com/ossez/framework/common/tests/dao/ReservationTest.java b/common/src/test/java/com/ossez/framework/common/tests/dao/ReservationTest.java new file mode 100644 index 0000000..8cb9447 --- /dev/null +++ b/common/src/test/java/com/ossez/framework/common/tests/dao/ReservationTest.java @@ -0,0 +1,173 @@ +package com.ossez.framework.common.tests.dao; + + +import com.ossez.framework.common.dao.Factory; +import com.ossez.framework.common.dao.factories.CarFactory; +import com.ossez.framework.common.models.CarType; +import com.ossez.framework.common.models.orm.CarInventory; +import com.ossez.framework.common.models.orm.CarReservation; +import com.ossez.framework.common.models.request.ReservationRequest; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.RandomUtils; +import org.apache.commons.lang3.StringUtils; +import org.junit.After; +import org.junit.jupiter.api.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.validation.ValidationException; +import java.util.Date; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * ReservationTest Testing + * + * @author YuCheng Hu + */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class ReservationTest { + private static Logger logger = LoggerFactory.getLogger(ReservationTest.class); + + @BeforeEach + protected void setUp() throws Exception { + Factory.beginTransaction(); + } + + @AfterEach + protected void tearDown() throws Exception { + Factory.commitTransaction(); + } + + /** + * Tests JPA and database connection + */ + @Test + public void testGetQIndex() throws ValidationException { + CarInventory carInventory = CarFactory.getCarInventoryById(1L); + logger.debug("carInventory Name for Id 1 - {}/{}", carInventory.getCarName(), carInventory.getCarType()); + + // make sure the reportManufacturer was found + assertNotNull(carInventory); + } + + /** + * Tests to check the size of Inventory + */ + @Test + public void testSizeOfInventory() throws ValidationException { + ReservationRequest reservationRequest = createReservationRequest(); + List carInventoryList = CarFactory.getCarInventory(reservationRequest.getCarType()); + logger.debug("carInventory List - {}/{}", reservationRequest.getCarType(), carInventoryList.size()); + } + + /** + * Test Save database for Reservation + * + * @throws ValidationException + */ + @Test + public void testAddRecordToReservation() throws ValidationException { + ReservationRequest reservationRequest = createReservationRequest(); + List carInventoryList = CarFactory.getCarInventory(reservationRequest.getCarType()); + + // + CarReservation carReservation = CarFactory.createReservation(reservationRequest, carInventoryList.get(0)); + logger.debug("carReservation CN - {}", carReservation.getId()); + } + + + /** + * MAIN TEST Function for Reservation logic + * + * @throws ValidationException + */ + @Test + public void testMakeReservation() throws ValidationException { + CarInventory carInventory = null; + String confirmationNumber = null; + + // Build Request + ReservationRequest reservationRequest = createReservationRequest(); + + // Check Inventory + List carInventoryList = checkInventoryAvailable(reservationRequest); + if (CollectionUtils.isNotEmpty(carInventoryList)) { + logger.debug("carInventory List - {}/{}", reservationRequest.getCarType(), carInventoryList.size()); + carInventory = carInventoryList.get(RandomUtils.nextInt(0, carInventoryList.size())); + } + + // Make Reservation + if (ObjectUtils.isNotEmpty(carInventory)) { + confirmationNumber = processReservation(reservationRequest, carInventory); + } else { + logger.debug("NO carInventory"); + } + + // UPDATE Inventory + if (StringUtils.isNotEmpty(confirmationNumber)) + updateInventory(carInventory, confirmationNumber); + + + logger.debug("confirmation Number - [{}]", carInventory.getConfirmationNumber()); + assertNotNull(carInventory.getConfirmationNumber()); + } + + /** + * Build reservationRequest + * + * @return + */ + private ReservationRequest createReservationRequest() { + ReservationRequest reservationRequest = new ReservationRequest(); + reservationRequest.setDateReservationStart(new Date()); + reservationRequest.setDurationReservation(2); + reservationRequest.setCarType(CarType.SUV); + + return reservationRequest; + } + + /** + * Check checkInventory Size + * + * @param reservationRequest + * @return + */ + private List checkInventoryAvailable(ReservationRequest reservationRequest) { + return CarFactory.getCarInventory(reservationRequest.getCarType()); + } + + + /** + * Process Reservation and get confirmationNumber + * + * @param reservationRequest + * @param carInventory + * @return + */ + private String processReservation(ReservationRequest reservationRequest, CarInventory carInventory) { + CarReservation carReservation = CarFactory.createReservation(reservationRequest, carInventory); + logger.debug("carReservation CN - {}", carReservation.getConfirmationNumber()); + return carReservation.getConfirmationNumber(); + } + + + /** + * Save CarInventory + * + * @param carInventory + * @param confirmationNumber + * @return + */ + private CarInventory updateInventory(CarInventory carInventory, String confirmationNumber) { + carInventory.setConfirmationNumber(confirmationNumber); + + CarFactory.saveCarInventory(carInventory); + logger.debug("carInventory CN - {}", carInventory.getConfirmationNumber()); + return carInventory; + } +} + + diff --git a/common/src/test/resources/ehcache.xml b/common/src/test/resources/ehcache.xml new file mode 100644 index 0000000..afb0017 --- /dev/null +++ b/common/src/test/resources/ehcache.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/common/src/test/resources/hibernate.cfg.xml b/common/src/test/resources/hibernate.cfg.xml new file mode 100644 index 0000000..1f4ba40 --- /dev/null +++ b/common/src/test/resources/hibernate.cfg.xml @@ -0,0 +1,34 @@ + + + + + 100 + true + 500 + thread + true + true + true + org.hibernate.dialect.SQLServer2012Dialect + + + com.zaxxer.hikari.hibernate.HikariConnectionProvider + + HikariPool-Azure + 5 + 10 + 30000 + SELECT 1 + + + true + org.hibernate.cache.ehcache.EhCacheRegionFactory + + + + + + + + diff --git a/common/src/test/resources/hibernate.properties b/common/src/test/resources/hibernate.properties new file mode 100644 index 0000000..10b56fd --- /dev/null +++ b/common/src/test/resources/hibernate.properties @@ -0,0 +1,6 @@ +hibernate.connection.driver_class = org.h2.Driver +hibernate.dialect = org.hibernate.dialect.H2Dialect +hibernate.connection.url=jdbc:h2:file:~/test;MODE=Mysql;DB_CLOSE_DELAY=-1;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE +#hibernate.connection.url=jdbc:h2:mem:test;MODE=Mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=RUNSCRIPT FROM 'classpath:schema/h2.sql' +hibernate.connection.username=sa +hibernate.connection.password= diff --git a/common/src/test/resources/log4j.xml b/common/src/test/resources/log4j.xml new file mode 100644 index 0000000..4739d89 --- /dev/null +++ b/common/src/test/resources/log4j.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/test/resources/log4j2.xml b/common/src/test/resources/log4j2.xml new file mode 100644 index 0000000..4739d89 --- /dev/null +++ b/common/src/test/resources/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/test/resources/logback.xml b/common/src/test/resources/logback.xml new file mode 100644 index 0000000..8599e4f --- /dev/null +++ b/common/src/test/resources/logback.xml @@ -0,0 +1,21 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + + + + + + + + diff --git a/common/src/test/resources/schema/h2.sql b/common/src/test/resources/schema/h2.sql new file mode 100644 index 0000000..29ccd49 --- /dev/null +++ b/common/src/test/resources/schema/h2.sql @@ -0,0 +1,59 @@ +CREATE SCHEMA IF NOT EXISTS CRD; + +create table IF NOT EXISTS CRD.CAR_INVENTORY +( + ID INT auto_increment, + CAR_NAME VARCHAR2, + CAR_TYPE int, + uuid VARCHAR2, + CONFIRMATION_NUMBER VARCHAR2, + dateC DATETIME, + dateM DATETIME +); + +create unique index IF NOT EXISTS CRD.CAR_INVENTORY_ID_UINDEX + on CRD.CAR_INVENTORY (ID); + +alter table CRD.CAR_INVENTORY + add constraint IF NOT EXISTS CAR_INVENTORY_PK + primary key (ID); + +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('Toyota', 0, now(), now()); +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('Toyota', 1, now(), now()); +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('Toyota', 2, now(), now()); +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('GMC', 0, now(), now()); +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('GMC', 1, now(), now()); +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('GMC', 2, now(), now()); +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('SUBARU', 0, now(), now()); +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('SUBARU', 1, now(), now()); +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('SUBARU', 2, now(), now()); +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, dateM, dateC) +VALUES ('SUBARU', 1, now(), now()); + + +INSERT INTO CRD.CAR_INVENTORY (CAR_NAME, CAR_TYPE, CONFIRMATION_NUMBER, dateM, dateC) +VALUES ('Toyota', 1, 'XX', now(), now()); + + +create table IF NOT EXISTS CRD.CAR_RESERVATION +( + ID INT auto_increment, + CAR_INVENTORY_ID INT, + CONFIRMATION_NUMBER VARCHAR2, + uuid VARCHAR2, + DATE_RESERVATION_START DATETIME, + DATE_RESERVATION_END DATETIME, + DATE_ACTUAL_START DATETIME, + DATE_ACTUAL_END DATETIME, + dateC DATETIME, + dateM DATETIME +); diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6e476c8 --- /dev/null +++ b/pom.xml @@ -0,0 +1,390 @@ + + + 4.0.0 + + com.ossez.framework + orm-factory-parent + 0.0.1-SNAPSHOT + pom + + Framework-Orm-Factory + Demo for Framework Orm Factory Query Data + https://github.com/honeymoose/Framework-Orm-Factory.git + + + + + + YuCheng Hu + honeymoose + huyuchengus@gmail.com + -5 + Open Source + + Sr. Java Developer + + + + + + + MIT License + https://www.opensource.org/licenses/mit-license.php + repo + + + + + common + + + + + 11 + UTF-8 + UTF-8 + + + 1.7.30 + 1.2.17 + 2.2 + + + 2.11.0 + 2.6 + 3.11 + 1.4 + 3.0.0 + + + 30.1.1-jre + + + 4.3.5.Final + + + 4.3.1.Final + + + 7.0.42 + 2.6.8 + 2.3.2 + + + 2.12.4 + + + 2.2 + 1.3 + + + 1.9.0 + 2.4.4 + 1.18.20 + 1.3 + 1.33 + 3.0.0 + 2.21.0 + 3.8.1 + + + + + + + + + + + + + + + ch.qos.logback + logback-classic + 1.2.5 + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.apache.commons + commons-lang3 + 3.12.0 + + + commons-io + commons-io + ${commons-io.version} + + + org.apache.commons + commons-compress + 1.20 + + + org.apache.commons + commons-math3 + 3.6.1 + + + org.apache.velocity + velocity + 1.7 + + + antlr + antlr + 2.7.6 + + + + + joda-time + joda-time + 2.10.13 + + + org.dom4j + dom4j + 2.1.3 + + + commons-cli + commons-cli + 1.4 + + + org.apache.velocity + velocity-tools + 2.0 + + + jaxen + jaxen + 1.1.6 + + + com.google.guava + guava + ${guava.version} + + + com.google.gdata + core + 1.47.1 + + + org.ow2.orchestra.eclipse.birt + org.ow2.orchestra.eclipse.birt.core + 3.7.0 + + + org.ow2.orchestra.eclipse.birt + org.ow2.orchestra.eclipse.birt.report.engine + 3.7.0 + + + commons-net + commons-net + 2.0 + + + com.mchange + mchange-commons-java + 0.2.9 + + + org.jasypt + jasypt + 1.5 + + + + httpunit + httpunit + 1.7 + + + net.sf.jazzy + jazzy + 0.5.2-rtext-1.4.1 + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + + + rome + rome + 0.9 + + + + org.apache.httpcomponents + httpmime + 4.5.1 + + + + org.jsoup + jsoup + 1.7.2 + + + + net.lingala.zip4j + zip4j + 1.3.2 + + + + + com.h2database + h2 + 1.4.200 + + + com.zaxxer + HikariCP + 3.4.5 + + + org.hibernate + hibernate-ehcache + 5.3.12.Final + + + org.hibernate + hibernate-search-orm + 5.10.7.Final + + + org.hibernate.validator + hibernate-validator + 6.0.20.Final + + + javax.el + javax.el-api + 3.0.0 + + + org.jasypt + jasypt-hibernate4 + 1.9.3 + + + + + org.springframework + spring-test + 5.3.13 + + + + + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + + + org.junit.jupiter + junit-jupiter-api + 5.7.0 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.7.0 + test + + + org.hamcrest + hamcrest + ${hamcrest.version} + test + + + org.hamcrest + hamcrest-all + ${hamcrest-all.version} + test + + + + + package + + + maven-compiler-plugin + 3.8.1 + + ${java.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + true + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + + diff --git a/src/main/java/com/crd/Main.java b/src/main/java/com/crd/Main.java new file mode 100644 index 0000000..fe3eb80 --- /dev/null +++ b/src/main/java/com/crd/Main.java @@ -0,0 +1,91 @@ +package com.crd; + +import java.util.Properties; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Options; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Main { + private static final Logger logger = LoggerFactory.getLogger(Main.class); + + private static Options options = new Options(); + private static Properties properties = new Properties(); + + private static CommandLine cl = null; + + private static boolean dryRun = false; + private static int limit = 0; + private static boolean force = false; + + public static void main(String[] args) { + + // get the idx feed properties file + Main.parseProperties(); + + // load console options + Main.parseCommandLine(args); + + logger.debug("Starting feeds..."); + System.out.println("starting feeds..."); + + // execute the feeds + Main.executeFeeds(); + + } + + /** + * Executes the feeds specified in the feeds.properties file. + */ + private static void executeFeeds() { + + } + + /** + * Parses the properties file to get a list of all feeds. + */ + private static void parseProperties() { + try { + // load the properties file + logger.debug("Parsing properties"); + Main.properties.load(Main.class.getClassLoader().getResourceAsStream("rets.properties")); + + // load the feeds + + } catch (Exception ex) { + ex.printStackTrace(); + logger.error("Could not parse feed properties", ex); + } + } + + /** + * Handles creation of console options. + */ + private static void parseCommandLine(String[] args) { + + // parse command line options + CommandLineParser parser = new GnuParser(); + + try { + Main.cl = parser.parse(Main.options, args); + + // get the dry run option + Main.dryRun = Main.cl.hasOption("d"); + logger.trace("Value of dryRun: " + dryRun); + + // get the limit option + // Main.limit = Utility.parseInt(Main.cl.getOptionValue("l", "0")); + logger.trace("Value of limit: " + Main.limit); + + // get the force option + Main.force = Main.cl.hasOption("u"); + logger.trace("Value of force: " + Main.force); + } catch (Exception ex) { + logger.error("An error ocurred parsing command line arguments", ex); + } + } +} diff --git a/src/main/java/com/crd/entity/HeatMapData.java b/src/main/java/com/crd/entity/HeatMapData.java new file mode 100644 index 0000000..1b7ee7c --- /dev/null +++ b/src/main/java/com/crd/entity/HeatMapData.java @@ -0,0 +1,63 @@ +package com.crd.entity; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serializable; + +/** + * Heatmap Data object + * + * @author YuCheng + */ +public class HeatMapData implements Serializable { + private static final long serialVersionUID = 5530454436970805656L; + + private static Logger logger = LoggerFactory.getLogger(HeatMapData.class); + + private String timestamp; + private String AlertId; + private String Severity; + private String accurateValue; + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getAlertId() { + return AlertId; + } + + public void setAlertId(String alertId) { + AlertId = alertId; + } + + public String getSeverity() { + return Severity; + } + + public void setSeverity(String severity) { + Severity = severity; + } + + public String getAccurateValue() { + return accurateValue; + } + + public void setAccurateValue(String accurateValue) { + this.accurateValue = accurateValue; + } + + /** + * Constructor + */ + public HeatMapData() { + + } + + +} \ No newline at end of file diff --git a/src/main/java/com/crd/overview/HelloWorld.java b/src/main/java/com/crd/overview/HelloWorld.java new file mode 100644 index 0000000..088a22b --- /dev/null +++ b/src/main/java/com/crd/overview/HelloWorld.java @@ -0,0 +1,16 @@ +package com.crd.overview; + +/** + * Java Tutorial + * + * This is my first java program. This will print 'Hello World' as the output This is an example of multi-line comments + * + * @author YuCheng + * + */ +public class HelloWorld { + public static void main(String[] args) { + + System.out.println("Hello World"); + } +} diff --git a/src/main/resources/html/cors.html b/src/main/resources/html/cors.html new file mode 100644 index 0000000..5759bc2 --- /dev/null +++ b/src/main/resources/html/cors.html @@ -0,0 +1,56 @@ + + + + + CORS TESTING + + + + + + + +
+

CORS TESTING

+ +

Update to your target API address:

+ +

  +

+

Update to your Bearer Token:

+ +

  +

+ +

+ + + + + + + + + + diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..632222f --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,101 @@ + + + + + + /home/logs/reoc/services/ + + + + + + + + + + + + + + + + + + %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n + + + + + + + + + + + + + + + %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n + + + + + + + + + + + + + + + %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n + + + + + + + + + + + + + + + %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/sample-data.csv b/src/main/resources/sample-data.csv new file mode 100644 index 0000000..bf7081e --- /dev/null +++ b/src/main/resources/sample-data.csv @@ -0,0 +1,6 @@ +Jill,Doe +Joe,Doe +Justin,Doe +Jane,Doe +John,Doe +YuCheng,HU diff --git a/src/main/resources/schema-all.sql b/src/main/resources/schema-all.sql new file mode 100644 index 0000000..e472ce1 --- /dev/null +++ b/src/main/resources/schema-all.sql @@ -0,0 +1,7 @@ +DROP TABLE people IF EXISTS; + +CREATE TABLE people ( + person_id BIGINT IDENTITY NOT NULL PRIMARY KEY, + first_name VARCHAR(20), + last_name VARCHAR(20) +); diff --git a/src/test/java/com/crd/tests/VariableTest.java b/src/test/java/com/crd/tests/VariableTest.java new file mode 100644 index 0000000..0d2db64 --- /dev/null +++ b/src/test/java/com/crd/tests/VariableTest.java @@ -0,0 +1,27 @@ +package com.crd.tests; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * @author YuCheng + */ +public class VariableTest { + + private final static Logger logger = LoggerFactory.getLogger(VariableTest.class); + + /** + * Do RetsServerConnection Test + */ + @Test + public void testStaticVariableChange() { + + } + +} diff --git a/src/test/resources/log4j2.xml b/src/test/resources/log4j2.xml new file mode 100644 index 0000000..ff28157 --- /dev/null +++ b/src/test/resources/log4j2.xml @@ -0,0 +1,97 @@ + + + + + + /home/logs/reoc/services/ + + + + + + + + + + + + + + + + + + %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n + + + + + + + + + + + + + + + %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n + + + + + + + + + + + + + + + %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n + + + + + + + + + + + + + + + %-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml new file mode 100644 index 0000000..8599e4f --- /dev/null +++ b/src/test/resources/logback.xml @@ -0,0 +1,21 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + + + + + + + +