galovics commented on code in PR #2453:
URL: https://github.com/apache/fineract/pull/2453#discussion_r928878978
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java:
##########
@@ -180,16 +180,14 @@ public final class Client extends
AbstractPersistableCustom {
@Column(name = "submittedon_date", nullable = true)
private LocalDate submittedOnDate;
- @ManyToOne(optional = true, fetch = FetchType.LAZY)
- @JoinColumn(name = "submittedon_userid", nullable = true)
- private AppUser submittedBy;
+ // Deprecated since common Auditable fields were introduced. Columns and
data left untouched to help migration.
- @Column(name = "updated_on", nullable = true)
- private LocalDate updatedOnDate;
+ // @Column(name = "updated_on", nullable = true)
Review Comment:
Can we use multi-line comment here? Sorry, I know it's a minor thing but it
groups these lines well together and nobody is going to confuse it with actual
comments that could be deleted. Thanks.
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableWithUTCDateTimeCustom.java:
##########
@@ -0,0 +1,108 @@
+/**
+ * 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.fineract.infrastructure.core.domain;
+
+import static
org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.CREATED_BY_DB_FIELD;
+import static
org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.CREATED_DATE_DB_FIELD;
+import static
org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.LAST_MODIFIED_BY_DB_FIELD;
+import static
org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.LAST_MODIFIED_DATE_DB_FIELD;
+
+import java.time.OffsetDateTime;
+import java.util.Optional;
+import javax.persistence.Column;
+import javax.persistence.MappedSuperclass;
+import org.apache.fineract.infrastructure.core.service.DateUtils;
+import org.springframework.data.domain.Auditable;
+import org.springframework.data.jpa.domain.AbstractAuditable;
+
+/**
+ * A custom copy of {@link AbstractAuditable} to override the column names
used on database. It also uses OffsetDateTime
+ * for created and modified. The datetimes will be converted from tenant TZ to
UTC before storing (automatically
+ * happens) and converted from System TZ to tenant TZ after fetching from DB
+ *
+ * Abstract base class for auditable entities. Stores the audit values in
persistent fields.
+ */
+@MappedSuperclass
+public abstract class AbstractAuditableWithUTCDateTimeCustom extends
AbstractPersistableCustom
+ implements Auditable<Long, Long, OffsetDateTime> {
+
+ private static final long serialVersionUID = 141481953116476081L;
+
+ @Column(name = CREATED_BY_DB_FIELD, nullable = false)
+ private Long createdBy;
+
+ @Column(name = CREATED_DATE_DB_FIELD, nullable = false)
+ private OffsetDateTime createdDate;
+
+ @Column(name = LAST_MODIFIED_BY_DB_FIELD, nullable = false)
+ private Long lastModifiedBy;
+
+ @Column(name = LAST_MODIFIED_DATE_DB_FIELD, nullable = false)
+ private OffsetDateTime lastModifiedDate;
+
+ @Override
+ public Optional<Long> getCreatedBy() {
+ return Optional.ofNullable(this.createdBy);
+ }
+
+ @Override
+ public void setCreatedBy(final Long createdBy) {
+ this.createdBy = createdBy;
+ }
+
+ @Override
+ public Optional<OffsetDateTime> getCreatedDate() {
+ if (this.createdDate == null) {
+ return Optional.empty();
+ } else {
+ return Optional.of(this.createdDate
+
.withOffsetSameInstant(DateUtils.getDateTimeZoneOfTenant().getRules().getOffset(this.createdDate.toInstant())));
+ }
+ }
+
+ @Override
+ public void setCreatedDate(final OffsetDateTime createdDate) {
+ this.createdDate = createdDate;
+ }
+
+ @Override
+ public Optional<Long> getLastModifiedBy() {
+ return Optional.ofNullable(this.lastModifiedBy);
+ }
+
+ @Override
+ public void setLastModifiedBy(final Long lastModifiedBy) {
+ this.lastModifiedBy = lastModifiedBy;
+ }
+
+ @Override
+ public Optional<OffsetDateTime> getLastModifiedDate() {
+ if (this.lastModifiedDate == null) {
+ return Optional.empty();
+ } else {
+ return Optional.of(this.lastModifiedDate
+
.withOffsetSameInstant(DateUtils.getDateTimeZoneOfTenant().getRules().getOffset(this.lastModifiedDate.toInstant())));
Review Comment:
UTC here too?
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/AbstractAuditableWithUTCDateTimeCustom.java:
##########
@@ -0,0 +1,108 @@
+/**
+ * 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.fineract.infrastructure.core.domain;
+
+import static
org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.CREATED_BY_DB_FIELD;
+import static
org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.CREATED_DATE_DB_FIELD;
+import static
org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.LAST_MODIFIED_BY_DB_FIELD;
+import static
org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.LAST_MODIFIED_DATE_DB_FIELD;
+
+import java.time.OffsetDateTime;
+import java.util.Optional;
+import javax.persistence.Column;
+import javax.persistence.MappedSuperclass;
+import org.apache.fineract.infrastructure.core.service.DateUtils;
+import org.springframework.data.domain.Auditable;
+import org.springframework.data.jpa.domain.AbstractAuditable;
+
+/**
+ * A custom copy of {@link AbstractAuditable} to override the column names
used on database. It also uses OffsetDateTime
+ * for created and modified. The datetimes will be converted from tenant TZ to
UTC before storing (automatically
+ * happens) and converted from System TZ to tenant TZ after fetching from DB
+ *
+ * Abstract base class for auditable entities. Stores the audit values in
persistent fields.
+ */
+@MappedSuperclass
+public abstract class AbstractAuditableWithUTCDateTimeCustom extends
AbstractPersistableCustom
+ implements Auditable<Long, Long, OffsetDateTime> {
+
+ private static final long serialVersionUID = 141481953116476081L;
+
+ @Column(name = CREATED_BY_DB_FIELD, nullable = false)
+ private Long createdBy;
+
+ @Column(name = CREATED_DATE_DB_FIELD, nullable = false)
+ private OffsetDateTime createdDate;
+
+ @Column(name = LAST_MODIFIED_BY_DB_FIELD, nullable = false)
+ private Long lastModifiedBy;
+
+ @Column(name = LAST_MODIFIED_DATE_DB_FIELD, nullable = false)
+ private OffsetDateTime lastModifiedDate;
+
+ @Override
+ public Optional<Long> getCreatedBy() {
+ return Optional.ofNullable(this.createdBy);
+ }
+
+ @Override
+ public void setCreatedBy(final Long createdBy) {
+ this.createdBy = createdBy;
+ }
+
+ @Override
+ public Optional<OffsetDateTime> getCreatedDate() {
+ if (this.createdDate == null) {
+ return Optional.empty();
+ } else {
+ return Optional.of(this.createdDate
Review Comment:
Shouldn't we use UTC here?
##########
fineract-provider/src/main/java/org/springframework/data/auditing/CustomAuditingHandler.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.springframework.data.auditing;
+
+import java.time.temporal.TemporalAccessor;
+import java.util.Optional;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fineract.infrastructure.core.auditing.CustomDateTimeProvider;
+import
org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDateTimeCustom;
+import org.springframework.core.log.LogMessage;
+import org.springframework.data.domain.AuditorAware;
+import org.springframework.data.mapping.PersistentEntity;
+import org.springframework.data.mapping.PersistentProperty;
+import org.springframework.data.mapping.context.MappingContext;
+import org.springframework.data.mapping.context.PersistentEntities;
+import org.springframework.util.Assert;
+
+/**
+ * Due to the package-private visibility of the Auditor, temporarely The
CustomAuditingHandler must be placed in the
+ * same package. Later when we don't need to distinct the Auditable entities
by interface anymore, it will be reworked.
+ */
+public class CustomAuditingHandler extends AuditingHandler {
+
+ private static final Log logger =
LogFactory.getLog(CustomAuditingHandler.class);
Review Comment:
Wrong Logger? Maybe just a copy paste error?
##########
fineract-provider/src/main/resources/db/changelog/tenant-store/parts/0005_jdbc_connection_string.xml:
##########
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
+ <changeSet author="fineract" id="1" context="tenant_store_db">
+ <update tableName="tenant_server_connections">
+ <column name="schema_connection_parameters"
value="serverTimezone=UTC&useLegacyDatetimeCode=false&sessionVariables=time_zone='-00:00'"/>
Review Comment:
Is this applicable for every DB? MySQL/MariaDB/PostgreSQL?
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java:
##########
@@ -219,9 +219,9 @@ public class Loan extends AbstractPersistableCustom {
@Column(name = "submittedon_date")
private LocalDate submittedOnDate;
- @ManyToOne(optional = true, fetch = FetchType.LAZY)
- @JoinColumn(name = "submittedon_userid", nullable = true)
- private AppUser submittedBy;
+ // @ManyToOne(optional = true, fetch = FetchType.LAZY)
Review Comment:
I assume this also calls for the same comment as for in the Client class,
doesn't it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]