Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Sohan Kumar Dey <[email protected]>
  • Loading branch information
Sohandey committed Apr 30, 2024
2 parents 1da518a + b6a7483 commit e75ca41
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
Expand All @@ -18,6 +19,7 @@
*
* @author Sowmya
*/
@EnableCaching
@SpringBootApplication(exclude = HibernateDaoConfig.class)
@Import(value = { java.lang.String.class, DummyPartnerCheckUtil.class, RestHelper.class, IdRepoSecurityManager.class })
@ComponentScan(basePackages = { "io.mosip.*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public ResponseWrapper<PageDto<CredentialRequestIdsDto>> getRequestIds(
@RequestParam(value = "effectivedtimes") @ApiParam(value = "Effective date time") @Nullable String effectivedtimes,
@RequestParam(value = "pageNumber", defaultValue = "0") @ApiParam(value = "page number for the requested data", defaultValue = "0") int page,
@RequestParam(value = "pageSize", defaultValue = "1") @ApiParam(value = "page size for the request data", defaultValue = "1") int size,
@RequestParam(value = "orderBy", defaultValue = "upd_dtimes") @ApiParam(value = "sort the requested data based on param value", defaultValue = "updateDateTime") String orderBy,
@RequestParam(value = "orderBy", defaultValue = "updateDateTime") @ApiParam(value = "sort the requested data based on param value", defaultValue = "updateDateTime") String orderBy,
@RequestParam(value = "direction", defaultValue = "DESC") @ApiParam(value = "order the requested data based on param", defaultValue = "ASC") String direction) {
ResponseWrapper<PageDto<CredentialRequestIdsDto>> responseWrapper =
credentialRequestService.getRequestIds(statusCode, effectivedtimes, page, size, orderBy, direction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ private String encryptDecryptData(ApiName api, String request) {
cryptoRequest.setApplicationId(EnvUtil.getAppId());
cryptoRequest.setData(request);
cryptoRequest.setReferenceId(EnvUtil.getCredCryptoRefId());
requestWrapper.setRequest(cryptoRequest);
cryptoRequest.setTimeStamp(DateUtils.getUTCCurrentDateTime());
requestWrapper.setRequest(cryptoRequest);
ResponseWrapper<Map<String, String>> restResponse = restUtil.postApi(api, null, null, null,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.mosip.credential.request.generator.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import io.mosip.credential.request.generator.entity.CredentialEntity;
import io.mosip.idrepository.core.dto.CredentialIssueStatusResponse;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class CacheUtil {

@Autowired
CacheManager cacheManager;


@Cacheable(value = "credential_transaction", key = "#requestId")
public CredentialIssueStatusResponse setCredentialTransaction(String requestId, CredentialEntity credentialEntity, String id) {

return createCredentialIssueStatusResponse(requestId, credentialEntity, id);
}

@CachePut(value = "credential_transaction", key = "#requestId")
public CredentialIssueStatusResponse updateCredentialTransaction(String requestId, CredentialEntity credentialEntity, String id) {

return createCredentialIssueStatusResponse(requestId, credentialEntity, id);
}


public CredentialIssueStatusResponse createCredentialIssueStatusResponse(String requestId, CredentialEntity credentialEntity, String id) {
CredentialIssueStatusResponse credentialIssueStatusResponse = new CredentialIssueStatusResponse();
credentialIssueStatusResponse.setId(id);
credentialIssueStatusResponse.setRequestId(requestId);
credentialIssueStatusResponse.setStatusCode(credentialEntity.getStatusCode());
credentialIssueStatusResponse.setUrl(credentialEntity.getDataShareUrl());
return credentialIssueStatusResponse;
}

public CredentialIssueStatusResponse getCredentialTransaction(String requestId) {
return cacheManager.getCache("credential_transaction").get(requestId, CredentialIssueStatusResponse.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.mosip.credential.request.generator.dto.Event;
import io.mosip.credential.request.generator.entity.CredentialEntity;
import io.mosip.credential.request.generator.exception.CredentialRequestGeneratorException;
import io.mosip.credential.request.generator.util.CacheUtil;
import io.mosip.credential.request.generator.util.Utilities;
import io.mosip.idrepository.core.dto.CredentialIssueRequest;
import io.mosip.idrepository.core.dto.CredentialIssueRequestDto;
Expand All @@ -59,6 +60,9 @@ public class CredentialRequestServiceImplTest {

@Mock
private EnvUtil env;

@Mock
private CacheUtil cacheUtil;

@Mock
CredentialEntity credentialEntity;
Expand Down Expand Up @@ -87,6 +91,8 @@ public void testCreateCredentialIssuanceSuccess() throws JsonProcessingException
credentialIssueRequestDto.setCredentialType("MOSIP");
credentialIssueRequestDto.setId("123");
credentialIssueRequestDto.setEncrypt(true);
CredentialIssueStatusResponse credentialIssueStatusResponse = new CredentialIssueStatusResponse();
Mockito.when(cacheUtil.setCredentialTransaction(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(credentialIssueStatusResponse);
Mockito.when(objectMapper.writeValueAsString(Mockito.any())).thenReturn(credentialIssueRequestDto.toString());
ResponseWrapper<CredentialIssueResponse> credentialIssueResponseDto=credentialRequestServiceImpl.createCredentialIssuance(credentialIssueRequestDto);
assertEquals("123456", credentialIssueResponseDto.getResponse().getRequestId());
Expand All @@ -98,6 +104,8 @@ public void testCreateCredentialIssuanceByRidSuccess() throws JsonProcessingExce
credentialIssueRequestDto.setCredentialType("MOSIP");
credentialIssueRequestDto.setId("123");
credentialIssueRequestDto.setEncrypt(true);
CredentialIssueStatusResponse credentialIssueStatusResponse = new CredentialIssueStatusResponse();
Mockito.when(cacheUtil.setCredentialTransaction(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(credentialIssueStatusResponse);
Mockito.when(objectMapper.writeValueAsString(Mockito.any())).thenReturn(credentialIssueRequestDto.toString());
ResponseWrapper<CredentialIssueResponse> credentialIssueResponseDto=credentialRequestServiceImpl.createCredentialIssuanceByRid(credentialIssueRequestDto,"123456");
assertEquals("123456", credentialIssueResponseDto.getResponse().getRequestId());
Expand Down Expand Up @@ -222,6 +230,9 @@ public void testDataAccessLayerExceptionForGetCredentialRequestStatus() throws J

@Test
public void testEntityEmptyForGetCredentialRequestStatus() throws JsonProcessingException {
Mockito.when(cacheUtil.getCredentialTransaction(Mockito.anyString())).thenReturn(null);
CredentialIssueStatusResponse credentialIssueStatusResponse = new CredentialIssueStatusResponse();
Mockito.when(cacheUtil.setCredentialTransaction(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(credentialIssueStatusResponse);
Mockito.when(credentialDao.findById(Mockito.any())).thenReturn(Optional.empty());
ResponseWrapper<CredentialIssueStatusResponse> credentialIssueResponseDto=credentialRequestServiceImpl.getCredentialRequestStatus("1234");
assertNotNull(credentialIssueResponseDto.getErrors().get(0));
Expand Down Expand Up @@ -250,6 +261,12 @@ public void testUpdateCredentialStatusSuccess()
CredentialEntity credentialEntity = new CredentialEntity();
credentialEntity.setRequestId("1234");
Optional<CredentialEntity> entity = Optional.of(credentialEntity);
CredentialIssueRequestDto credentialIssueRequestDto = new CredentialIssueRequestDto();
credentialIssueRequestDto.setCredentialType("MOSIP");
credentialIssueRequestDto.setId("123");
credentialIssueRequestDto.setIssuer("test");
Mockito.when(objectMapper.readValue(credentialEntity.getRequest(), CredentialIssueRequestDto.class))
.thenReturn(credentialIssueRequestDto);
Mockito.when(credentialDao.findById(Mockito.any())).thenReturn(entity);
Event event = new Event();
CredentialStatusEvent credentialStatusEvent = new CredentialStatusEvent();
Expand Down
10 changes: 10 additions & 0 deletions id-repository/id-repository-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.mosip.idrepository.core.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

@ConditionalOnProperty(value = "spring.cache.type", havingValue = "redis")
@Configuration
public class RedisCacheConfig {

@Value("${mosip.credential.cache.expire-in-seconds:60}")
private Integer cacheExpireInSeconds;

@Bean
public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
Map<String, RedisCacheConfiguration> cacheConfigurations = new HashMap<>();
cacheConfigurations.put("credential_transaction", RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(cacheExpireInSeconds)));

return RedisCacheManager.builder(connectionFactory)
.withInitialCacheConfigurations(cacheConfigurations)
.build();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.mosip.idrepository.core.config;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.cache.CacheBuilder;

@ConditionalOnProperty(value = "spring.cache.type", havingValue = "simple", matchIfMissing = true)
@Configuration
public class SimpleCacheConfig extends CachingConfigurerSupport {

@Value("${mosip.credential.cache.size:100}")
private Integer cacheMaxSize;

@Value("${mosip.credential.cache.expire-in-seconds:60}")
private Integer cacheExpireInSeconds;


@Bean
@Override
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(buildMapCache("credential_transaction")));
return cacheManager;
}

private ConcurrentMapCache buildMapCache(String name) {
return new ConcurrentMapCache(name,
CacheBuilder.newBuilder()
.expireAfterWrite(cacheExpireInSeconds, TimeUnit.SECONDS)
.maximumSize(cacheMaxSize)
.build()
.asMap(), true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private <T extends UinInfo> void encryptDataOnSave(Serializable id, Object[] sta
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
try {
List<String> propertyNamesList = Arrays.asList(propertyNames);
if (entity instanceof Uin || entity instanceof UinDraft) {
if (entity instanceof Uin || entity instanceof UinHistory || entity instanceof UinDraft) {
int indexOfData = propertyNamesList.indexOf(UIN_DATA);
if (Objects.nonNull(state[indexOfData])) {
state[indexOfData] = securityManager.decrypt((byte[]) state[indexOfData], uinDataRefId);
Expand Down

0 comments on commit e75ca41

Please sign in to comment.