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

ES-421 Updated credential_transaction_id column length in credential_event_store table #1144

Merged
merged 5 commits into from
Dec 13, 2023
Merged
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
Expand Up @@ -24,7 +24,8 @@ public enum IdType {
/** The uin. */
UIN("UIN"),
/** The vid. */
VID("VID")
VID("VID"),
HANDLE("HANDLE")
;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package io.mosip.authentication.core.util;

import java.util.Map;
import java.util.Objects;

import io.mosip.authentication.core.logger.IdaLogger;
import io.mosip.kernel.core.exception.BaseUncheckedException;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.kernel.core.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import io.mosip.authentication.core.constant.IdAuthCommonConstants;
Expand All @@ -11,6 +17,8 @@
import io.mosip.authentication.core.indauth.dto.IdType;
import io.mosip.kernel.core.idvalidator.exception.InvalidIDException;

import static io.mosip.authentication.core.constant.IdAuthCommonConstants.SESSION_ID;

/**
* @author Manoj SP
* @author Nagarjuna
Expand All @@ -19,9 +27,14 @@
@Component
public class IdTypeUtil {

private static Logger mosipLogger = IdaLogger.getLogger(IdTypeUtil.class);

@Autowired
IdValidationUtil idValidator;

@Value("#{${mosip.ida.handle-types.regex}}")
private Map<String, String> handleTypesRegex;

public boolean validateUin(String uin) {
try {
if (Objects.nonNull(idValidator))
Expand All @@ -44,11 +57,36 @@ public boolean validateVid(String vid) {
}
}

public boolean validateHandle(String handle) {
try {
if(Objects.nonNull(handleTypesRegex)) {
if(StringUtils.isEmpty(handle))
return false;

int index = handle.lastIndexOf("@");
if(index <= 0)
return false;

String handleType = handle.substring(index);
if(!handleTypesRegex.containsKey(handleType))
return false;

return handle.matches(handleTypesRegex.get(handleType));
}
} catch (BaseUncheckedException e) {
mosipLogger.error(SESSION_ID, this.getClass().getSimpleName(), "VALIDATE_HANDLE",
"Failed to validate handle >> "+ e.getMessage());
}
return false;
}

public IdType getIdType(String id) throws IdAuthenticationBusinessException {
if (this.validateUin(id))
return IdType.UIN;
if (this.validateVid(id))
return IdType.VID;
if (this.validateHandle(id))
return IdType.HANDLE;
throw new IdAuthenticationBusinessException(
IdAuthenticationErrorConstants.INVALID_INPUT_PARAMETER.getErrorCode(),
String.format(IdAuthenticationErrorConstants.INVALID_INPUT_PARAMETER.getErrorMessage(),
Expand Down
2 changes: 1 addition & 1 deletion db_scripts/mosip_ida/ddl/ida-credential_event_store.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
CREATE TABLE ida.credential_event_store(
event_id character varying(36) NOT NULL,
event_topic character varying(256) NOT NULL,
credential_transaction_id character varying(36) NOT NULL,
credential_transaction_id character varying(64) NOT NULL,
publisher character varying(128),
published_on_dtimes timestamp,
event_object character varying,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\echo 'Upgrade Queries not required for the transition from 1.2.0.1-B5 to 1.2.0.1'

ALTER TABLE ida.credential_event_store ALTER COLUMN credential_transaction_id type character varying(36);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\echo 'Upgrade Queries not required for transition from 1.2.0.1-B5 to 1.2.0.1'

ALTER TABLE ida.credential_event_store ALTER COLUMN credential_transaction_id type character varying(64);