Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/public/transaction/statistics rest api #53

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* eGov SmartCity eGovernance suite aims to improve the internal efficiency,transparency,
* accountability and the service delivery of the government organizations.
*
* Copyright (C) 2018 eGovernments Foundation
*
* The updated version of eGov suite of products as by eGovernments Foundation
* is available at http://www.egovernments.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/ or
* http://www.gnu.org/licenses/gpl.html .
*
* In addition to the terms of the GPL license to be adhered to in using this
* program, the following additional terms are to be complied with:
*
* 1) All versions of this program, verbatim or modified must carry this
* Legal Notice.
* Further, all user interfaces, including but not limited to citizen facing interfaces,
* Urban Local Bodies interfaces, dashboards, mobile applications, of the program and any
* derived works should carry eGovernments Foundation logo on the top right corner.
*
* For the logo, please refer http://egovernments.org/html/logo/egov_logo.png.
* For any further queries on attribution, including queries on brand guidelines,
* please contact contact@egovernments.org
*
* 2) Any misrepresentation of the origin of the material is prohibited. It
* is required that all modified versions of this material be marked in
* reasonable ways as different from the original version.
*
* 3) This license does not grant any rights to any user of the program
* with regards to rights under trademark law for use of the trade names
* or trademarks of eGovernments Foundation.
*
* In case of any queries, you can reach eGovernments Foundation at contact@egovernments.org.
*
*/

package org.egov.restapi.model;

import org.egov.infra.persistence.validator.annotation.Numeric;
import org.egov.infra.persistence.validator.annotation.Required;
import org.egov.infra.validation.exception.ValidationError;
import org.egov.infra.validation.exception.ValidationException;
import org.egov.restapi.validator.annotation.NoFutureDate;
import org.egov.restapi.validator.annotation.OverlappedDateRange;
import org.egov.restapi.validator.annotation.ThisCityCode;

import javax.validation.constraints.Pattern;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@OverlappedDateRange(fromDate = "fromDate", toDate = "toDate", dateFormat = ETransactionRequest.DATE_FORMAT, message = "fromDate must be less than or equal to toDate")
public class ETransactionRequest {

private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");

private static final String DATE_PATTERN = "([0-3][0-9])-((0[0-9])|(1[0-2]))-(\\d\\d\\d\\d)";
protected static final String DATE_FORMAT = "dd-MM-yyyy";

@NoFutureDate(dateFormat = DATE_FORMAT)
@Pattern(regexp = DATE_PATTERN, message = "fromDate must be of dd-MM-yyyy pattern")
@Required
private String fromDate;

@NoFutureDate(dateFormat = DATE_FORMAT)
@Pattern(regexp = DATE_PATTERN, message = "fromDate must be of dd-MM-yyyy pattern")
@Required
private String toDate;

@ThisCityCode
@Numeric
@Required
private String ulbCode;

public ETransactionRequest() {
}

public ETransactionRequest(String fromDate, String toDate, String ulbCode) {
this.fromDate = fromDate;
this.toDate = toDate;
this.ulbCode = ulbCode;
}

public String getFromDate() {
return fromDate;
}

public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}

public String getToDate() {
return toDate;
}

public void setToDate(String toDate) {
this.toDate = toDate;
}

public String getUlbCode() {
return ulbCode;
}

public void setUlbCode(String ulbCode) {
this.ulbCode = ulbCode;
}

public Date getParsedFromDate() {
try {
return SIMPLE_DATE_FORMAT.parse(fromDate);
} catch (ParseException e) {
throw new ValidationException(new ValidationError("INVALID_DATE", "Invalid fromDate"));
}
}

public Date getParsedToDate() {
try {
return SIMPLE_DATE_FORMAT.parse(toDate);
} catch (ParseException e) {
throw new ValidationException(new ValidationError("INVALID_DATE", "Invalid toDate"));
}
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

ETransactionRequest that = (ETransactionRequest) o;


if (fromDate != null && !fromDate.equals(that.fromDate))
return false;
if (toDate != null && !toDate.equals(that.toDate))
return false;
return (ulbCode == that.ulbCode && ulbCode == null) || ulbCode.equals(that.ulbCode);

}

@Override
public String toString() {
return "ETransactionRequest{" +
"fromDate='" + fromDate + '\'' +
", toDate='" + toDate + '\'' +
", ulbCode='" + ulbCode + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import org.egov.eis.entity.Assignment;
import org.egov.infra.admin.master.entity.Boundary;
import org.egov.infra.admin.master.entity.BoundaryType;
import org.egov.infra.config.core.ApplicationThreadLocals;
import org.egov.infra.utils.DateUtils;
import org.egov.infra.validation.exception.ValidationError;
import org.egov.ptis.client.service.calculator.APTaxCalculator;
Expand Down Expand Up @@ -144,20 +143,13 @@ public class ValidationUtil {
@Autowired
private ApplicationContext beanProvider;

private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");
private static final Pattern DATE_PATTERN = Pattern.compile("([0-3][0-9])-((0[0-9])|(1[0-2]))-(\\d\\d\\d\\d)");

private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private static final String PINCODE_PATTERN = "^[1-9][0-9]{5}$";
private static final String GUARDIAN_PATTERN = "^[\\p{L} .'-]+$";
private static final String CAMEL_CASE_PATTERN = "([A-Z]+[a-z]+\\w+)+";
private static final String DIGITS_FLOAT_INT_DBL = "[-+]?[0-9]*\\.?[0-9]+";

static {
DATE_FORMAT.setLenient(false);
}

/**
* Validates Property Transfer request
*
Expand Down Expand Up @@ -648,77 +640,6 @@ private ErrorDetails validateAssignment(PropertyImpl property) {

}

/*
* Appends ValidationError to @param errorList
*/
public void validateRequiredFields(final List<ValidationError> errorList, final JsonElement object, final String... keys) {
if (!object.isJsonObject()) {
errorList.add(new ValidationError(JSON_CONVERSION_ERROR_CODE, "Expected a Object."));
return;
}
JsonObject jsonObject = object.getAsJsonObject();
for (final String key : keys) {
if (!jsonObject.has(key)) {
errorList.add(new ValidationError("MISSING_KEY", "Required \"" + key + "\""));
}
JsonElement valueElement = jsonObject.get(key);
if (valueElement.isJsonNull()) {
errorList.add(new ValidationError("NO_NULL_KEY", "Key \"" + key + "\" must not be null"));
}
}
}

/*
* Appends ValidationError to @param errorList
*/
public void validateETransactionRequest(final List<ValidationError> errorList, String ulbCode, Date fromDate, Date toDate) {
if (StringUtils.isBlank(ulbCode)) {
errorList.add(new ValidationError("NO_EMPTY_FIELD", RestApiConstants.THIRD_PARTY_ERR_CODE_ULBCODE_NO_REQ_MSG));
} else if (!ApplicationThreadLocals.getCityCode().equals(ulbCode)) {
errorList.add(new ValidationError(RestApiConstants.THIRD_PARTY_ERR_CODE_ULBCODE_NO_REQUIRED, "Invalid ULB Code"));
}

if (DateUtils.compareDates(fromDate, toDate)) {
errorList.add(new ValidationError("INVALID_DATE_RANGE", "toDate must be greater or equal to fromDate"));
}
Date endOfToday = DateUtils.endOfToday().toDate();
Date maxDate;
String maxDateParam;
if (DateUtils.compareDates(fromDate, toDate)) {
maxDate = fromDate;
maxDateParam = "fromDate";
} else {
maxDate = toDate;
maxDateParam = "toDate";
}
if (!maxDate.equals(endOfToday) && DateUtils.compareDates(maxDate, endOfToday)) {
errorList.add(new ValidationError("NO_FUTURE_DATE", String.format("%s(%s) must be less or equal to today (%s)",
maxDateParam, convertDateToString(maxDate), convertDateToString(endOfToday))));
}
}

/**
* Validate using regex and parse the date
* @param dateInString
* @return Date
* @throws ParseException
*/
public Date convertStringToDate(final String dateInString) throws ParseException {

Matcher matcher = DATE_PATTERN.matcher(dateInString);
if (!matcher.matches()) {
throw new ParseException("Invalid date", 0);
}
return DATE_FORMAT.parse(dateInString);
}

/**
* Convert date to string in dd-MM-yyyy format
*/
public String convertDateToString(final Date date) {
return DATE_FORMAT.format(date);
}

/**
* Validates Vacant Land details
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.egov.restapi.validator;

import org.egov.infra.config.core.ApplicationThreadLocals;
import org.egov.infra.utils.StringUtils;
import org.egov.restapi.validator.annotation.ThisCityCode;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class CityCodeValidator implements ConstraintValidator<ThisCityCode, String> {

ThisCityCode constraintAnnotation;

@Override
public void initialize(final ThisCityCode constraintAnnotation) {
this.constraintAnnotation = constraintAnnotation;
}

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if (StringUtils.isEmpty(value))
return false;
else {
return ApplicationThreadLocals.getCityCode().equals(value.trim());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* eGov SmartCity eGovernance suite aims to improve the internal efficiency,transparency,
* accountability and the service delivery of the government organizations.
*
* Copyright (C) 2017 eGovernments Foundation
*
* The updated version of eGov suite of products as by eGovernments Foundation
* is available at http://www.egovernments.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/ or
* http://www.gnu.org/licenses/gpl.html .
*
* In addition to the terms of the GPL license to be adhered to in using this
* program, the following additional terms are to be complied with:
*
* 1) All versions of this program, verbatim or modified must carry this
* Legal Notice.
* Further, all user interfaces, including but not limited to citizen facing interfaces,
* Urban Local Bodies interfaces, dashboards, mobile applications, of the program and any
* derived works should carry eGovernments Foundation logo on the top right corner.
*
* For the logo, please refer http://egovernments.org/html/logo/egov_logo.png.
* For any further queries on attribution, including queries on brand guidelines,
* please contact contact@egovernments.org
*
* 2) Any misrepresentation of the origin of the material is prohibited. It
* is required that all modified versions of this material be marked in
* reasonable ways as different from the original version.
*
* 3) This license does not grant any rights to any user of the program
* with regards to rights under trademark law for use of the trade names
* or trademarks of eGovernments Foundation.
*
* In case of any queries, you can reach eGovernments Foundation at contact@egovernments.org.
*
*/

package org.egov.restapi.validator;

import org.egov.infra.utils.DateUtils;
import org.egov.infra.utils.StringUtils;
import org.egov.restapi.validator.annotation.NoFutureDate;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class NoFutureDateValidator implements ConstraintValidator<NoFutureDate, String> {

private NoFutureDate noFutureDate;

@Override
public void initialize(final NoFutureDate noFutureDate) {
this.noFutureDate = noFutureDate;
}

@Override
public boolean isValid(final String value, final ConstraintValidatorContext arg1) {
if (StringUtils.isEmpty(value))
return true;
if (noFutureDate.dateFormat() == null) {
return false;
}
try {
SimpleDateFormat sdf = new SimpleDateFormat(noFutureDate.dateFormat());
sdf.setLenient(false);
Date date = sdf.parse(value);
Date endOfToday = DateUtils.endOfToday().toDate();
return date.before(endOfToday);
} catch (IllegalArgumentException | ParseException e) {
return false;
}
}

}
Loading