Skip to content

Commit

Permalink
ES-421 Updated credential_transaction_id column length in credential_…
Browse files Browse the repository at this point in the history
…event_store table (#1144)

* ES-421 Update ida-credential_event_store.sql

Signed-off-by: Anusha Sunkada <[email protected]>
Signed-off-by: ase-101 <[email protected]>

* ES-421 renamed file and added alter stmt

Signed-off-by: ase-101 <[email protected]>

* ES-421

Signed-off-by: ase-101 <[email protected]>

* ES-421

Signed-off-by: ase-101 <[email protected]>

* Fixed review comment

Signed-off-by: ase-101 <[email protected]>

---------

Signed-off-by: Anusha Sunkada <[email protected]>
Signed-off-by: ase-101 <[email protected]>
  • Loading branch information
ase-101 authored Dec 13, 2023
1 parent 0e08f23 commit 9b5c759
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 4 deletions.
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);

0 comments on commit 9b5c759

Please sign in to comment.