FINERACT-1932: Fineract modularization - fineract-cob
This commit is contained in:
committed by
Arnold Gálovics
parent
e090da2a01
commit
7452ea2552
-46
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.core.exceptionmapper;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.cob.exceptions.BusinessStepException;
|
||||
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
|
||||
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Provider
|
||||
@Component
|
||||
@Slf4j
|
||||
public class BusinessStepExceptionMapper implements ExceptionMapper<BusinessStepException> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(BusinessStepException exception) {
|
||||
final String globalisationMessageCode = "error.msg.invalid.request.body";
|
||||
final String defaultUserMessage = exception.getMessage();
|
||||
log.warn("Exception occurred", ErrorHandler.findMostSpecificException(exception));
|
||||
|
||||
final ApiParameterError error = ApiParameterError.parameterError(globalisationMessageCode, defaultUserMessage, "stepName");
|
||||
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(error).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.core.exceptionmapper;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.cob.exceptions.BusinessStepNotBelongsToJobException;
|
||||
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
|
||||
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Provider
|
||||
@Component
|
||||
@Slf4j
|
||||
public class BusinessStepNotBelongsToJobExceptionMapper implements ExceptionMapper<BusinessStepNotBelongsToJobException> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(BusinessStepNotBelongsToJobException exception) {
|
||||
final String globalisationMessageCode = "error.msg.invalid.request.body";
|
||||
final String defaultUserMessage = "One of the provided Business Steps does not belong to the provided Job Name.";
|
||||
log.warn("Exception occurred", ErrorHandler.findMostSpecificException(exception));
|
||||
|
||||
final ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
|
||||
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(error).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+10
-8
@@ -16,15 +16,17 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.cob;
|
||||
package org.apache.fineract.infrastructure.jobs.data;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
public interface COBBusinessStep<T extends AbstractPersistableCustom<Long>> {
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class JobParameterDTO {
|
||||
|
||||
T execute(T input);
|
||||
|
||||
String getEnumStyledName();
|
||||
|
||||
String getHumanReadableName();
|
||||
private String parameterName;
|
||||
private String parameterValue;
|
||||
}
|
||||
+10
-8
@@ -16,15 +16,17 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.cob.exceptions;
|
||||
package org.apache.fineract.infrastructure.jobs.data;
|
||||
|
||||
public class BusinessStepException extends RuntimeException {
|
||||
import java.util.Set;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
public BusinessStepException(String message) {
|
||||
super(message);
|
||||
}
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class JobParametersDTO {
|
||||
|
||||
public BusinessStepException(String message, Throwable t) {
|
||||
super(message, t);
|
||||
}
|
||||
private Set<JobParameterDTO> jobParameters;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 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.jobs.domain;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
|
||||
@Entity
|
||||
@Table(name = "batch_custom_job_parameters")
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class CustomJobParameter extends AbstractPersistableCustom<Long> {
|
||||
|
||||
@Column(name = "parameter_json", nullable = false, columnDefinition = "json")
|
||||
private String parameterJson;
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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.jobs.domain;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import org.apache.fineract.infrastructure.jobs.data.JobParameterDTO;
|
||||
|
||||
public interface CustomJobParameterRepository {
|
||||
|
||||
Long save(Set<JobParameterDTO> customJobParameters);
|
||||
|
||||
Optional<CustomJobParameter> findById(Long Id);
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 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.jobs.domain;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper;
|
||||
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
|
||||
import org.apache.fineract.infrastructure.jobs.data.JobParameterDTO;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
public class CustomJobParameterRepositoryImpl implements CustomJobParameterRepository {
|
||||
|
||||
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
private final DatabaseSpecificSQLGenerator databaseSpecificSQLGenerator;
|
||||
private final Gson gson = GoogleGsonSerializerHelper.createSimpleGson();
|
||||
|
||||
@Override
|
||||
public Long save(Set<JobParameterDTO> customJobParameters) {
|
||||
Objects.requireNonNull(customJobParameters);
|
||||
final String insertSQL = "INSERT INTO batch_custom_job_parameters (parameter_json) VALUES (%s)"
|
||||
.formatted(databaseSpecificSQLGenerator.castJson(":jsonString"));
|
||||
final String jsonString = gson.toJson(customJobParameters);
|
||||
SqlParameterSource parameters = new MapSqlParameterSource("jsonString", jsonString);
|
||||
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
|
||||
namedParameterJdbcTemplate.update(insertSQL, parameters, keyHolder);
|
||||
return databaseSpecificSQLGenerator.fetchPK(keyHolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<CustomJobParameter> findById(Long id) {
|
||||
Objects.requireNonNull(id);
|
||||
CustomJobParameterExtractor customJobParameterExtractor = new CustomJobParameterExtractor();
|
||||
SqlParameterSource parameters = new MapSqlParameterSource("id", id);
|
||||
return Optional.ofNullable(namedParameterJdbcTemplate.query(
|
||||
"SELECT cjp.parameter_json AS parameter_json FROM batch_custom_job_parameters cjp WHERE cjp.id = :id", parameters,
|
||||
customJobParameterExtractor));
|
||||
}
|
||||
|
||||
private static final class CustomJobParameterExtractor implements ResultSetExtractor<CustomJobParameter> {
|
||||
|
||||
@Override
|
||||
public CustomJobParameter extractData(ResultSet rs) throws SQLException, DataAccessException {
|
||||
CustomJobParameter jobParameter = null;
|
||||
if (rs.next()) {
|
||||
jobParameter = new CustomJobParameter();
|
||||
jobParameter.setParameterJson(rs.getString("parameter_json"));
|
||||
}
|
||||
return jobParameter;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+5
-2
@@ -16,6 +16,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.cob.exceptions;
|
||||
package org.apache.fineract.infrastructure.springbatch;
|
||||
|
||||
public class BusinessStepNotBelongsToJobException extends RuntimeException {}
|
||||
public abstract class SpringBatchJobConstants {
|
||||
|
||||
public static final String CUSTOM_JOB_PARAMETER_ID_KEY = "CUSTOM_JOB_PARAMETER_ID";
|
||||
}
|
||||
Reference in New Issue
Block a user