Skip to content

Commit

Permalink
MOSIP-29472 Cherry pick resident related changes from develop to rele…
Browse files Browse the repository at this point in the history
…ase 121x branch. (#957)

* MOSIP-29472 Fixed merge conflict

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Added API /locations/immediatechildren/{locationcode} (#904)

* MOSIP-29472 Create API dynamicfields/all.

* MOSIP-29472 Create API dynamicfields/all.

* MOSIP-29472 Create API dynamicfields/all.

* MOSIP-29472 Covered Junit for Dynamic field all API.

* MOSIP-29472 Covered Junit for Dynamic field all API.

* MOSIP-29472 Changed logic as per review comment.

* MOSIP-29472 Changed logic as per review comment.

* MOSIP-29472 Changed logic as per review comment.

* MOSIP-29472 Added API {{url}}/v1/masterdata/locations/immediatechildren/{locationCode}.

* MOSIP-29472 Removed un-used class.

* MOSIP-29472 Added Junit for new API /immediatechildren/locationcode

* MOSIP-29472 Added Junit for new API /immediatechildren/locationcode

* MOSIP-29472 Added Junit for new API /immediatechildren/locationcode

* MOSIP-29472 Added Junit for new API /immediatechildren/locationcode

* MOSIP-29472 Added Junit for new API /immediatechildren/locationcode

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Move dynamic field test method to master data service class

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Move dynamic field test method to master data service class

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Move dynamic field test method to master data service class

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Move dynamic field test method to master data service class

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Move dynamic field test method to master data service class

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Move dynamic field test method to master data service class

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Removed all

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Added version changes

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Added version changes

Signed-off-by: kameshsr <[email protected]>

* MOSIP-29472 Added version changes

Signed-off-by: kameshsr <[email protected]>

---------

Signed-off-by: kameshsr <[email protected]>
  • Loading branch information
kameshsr authored Apr 23, 2024
1 parent 0f85298 commit bd1b078
Show file tree
Hide file tree
Showing 18 changed files with 317 additions and 206 deletions.
6 changes: 3 additions & 3 deletions admin/admin-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>io.mosip.admin</groupId>
<artifactId>admin-parent</artifactId>
<version>1.2.0.1</version>
<version>1.2.1.0-SNAPSHOT</version>
</parent>
<artifactId>admin-service</artifactId>
<name>admin-service</name>
<version>1.2.0.1</version>
<version>1.2.1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<packaging>jar</packaging>
<properties>
Expand Down Expand Up @@ -216,7 +216,7 @@
<dependency>
<groupId>io.mosip.kernel</groupId>
<artifactId>kernel-auth-adapter</artifactId>
<version>${project.version}</version>
<version>${kernel-auth-adapter.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
Expand Down
4 changes: 2 additions & 2 deletions admin/hotlist-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.mosip.hotlist</groupId>
<artifactId>hotlist-service</artifactId>
<version>1.2.0.1</version>
<version>1.2.1.0-SNAPSHOT</version>
<name>Hotlist Service</name>
<description>Service to block/unblock ids in MOSIP</description>
<url>https://github.com/mosip/admin-services</url>
Expand Down Expand Up @@ -362,7 +362,7 @@
<dependency>
<groupId>io.mosip.kernel</groupId>
<artifactId>kernel-auth-adapter</artifactId>
<version>${kernel.version}</version>
<version>${kernel-auth-adapter.version}</version>
</dependency>
</dependencies>
<build>
Expand Down
4 changes: 2 additions & 2 deletions admin/kernel-masterdata-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<name>kernel-masterdata-service</name>
<description>Mosip commons project </description>
<url>https://github.com/mosip/commons</url>
<version>1.2.0.1</version>
<version>1.2.1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Expand Down Expand Up @@ -475,7 +475,7 @@
<dependency>
<groupId>io.mosip.kernel</groupId>
<artifactId>kernel-auth-adapter</artifactId>
<version>${project.version}</version>
<version>${kernel-auth-adapter.version}</version>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;

import javax.validation.Valid;
import javax.websocket.server.PathParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
Expand Down Expand Up @@ -39,7 +38,6 @@
import io.mosip.kernel.masterdata.dto.response.FilterResponseCodeDto;
import io.mosip.kernel.masterdata.dto.response.FilterResponseDto;
import io.mosip.kernel.masterdata.dto.response.PageResponseDto;
import io.mosip.kernel.masterdata.entity.DynamicField;
import io.mosip.kernel.masterdata.service.DynamicFieldService;
import io.mosip.kernel.masterdata.service.GenericService;
import io.mosip.kernel.masterdata.utils.AuditUtil;
Expand Down Expand Up @@ -93,6 +91,16 @@ public ResponseWrapper<DynamicFieldConsolidateResponseDto> getDynamicFieldByName
responseWrapper.setResponse(dynamicFieldService.getDynamicFieldByNameAndLangcode(fieldName,langCode,withValue));
return responseWrapper;
}

@ResponseFilter
@GetMapping("/{fieldName}")
@ApiOperation(value = " Service to fetch one dynamic field in all the languages")
public ResponseWrapper<List<DynamicFieldExtnDto>> getAllDynamicFieldByName(
@PathVariable("fieldName") String fieldName){
ResponseWrapper<List<DynamicFieldExtnDto>> responseWrapper = new ResponseWrapper<>();
responseWrapper.setResponse(dynamicFieldService.getAllDynamicFieldByName(fieldName));
return responseWrapper;
}


@ResponseFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,23 @@ public ResponseWrapper<LocationResponseDto> getImmediateChildrenByLocCodeAndLang
return responseWrapper;
}

/**
*
* @param locationCode location code
* @param languageCodes language codes
* @return list of location hierarchies
*/
@ResponseFilter
@GetMapping(value = "/immediatechildren/{locationcode}")
public ResponseWrapper<LocationResponseDto> getImmediateChildrenByLocCode(
@PathVariable("locationcode") String locationCode, @RequestParam("languageCodes") List<String> languageCodes) {

ResponseWrapper<LocationResponseDto> responseWrapper = new ResponseWrapper<>();
responseWrapper
.setResponse(locationHierarchyService.getImmediateChildrenByLocCode(locationCode, languageCodes));
return responseWrapper;
}

/**
* checks whether the given location name is valid or not
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import org.json.JSONArray;

import java.time.LocalDateTime;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ int updateDynamicField(String id, String description, String langCode, String da

/**
* update isDeleted as true
* @param id
* @param updatedDateTime
* @param updatedBy
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,7 @@ List<Location> findLocationByHierarchyLevelStartsWith(Short hierarchyLevel, Stri
@Query(value = "FROM Location l where l.langCode=?1 and l.hierarchyLevel=?2")
List<Location> getAllLocationsByLangCodeWithHierarchyLevel(String langCode, Short level);

@Query(value = "FROM Location l WHERE parentLocCode = ?1 AND l.langCode IN (?2) AND (l.isDeleted IS NULL OR l.isDeleted = false) AND l.isActive = true")
List<Location> findLocationHierarchyByParentLocCode(String parentLocCode, List<String> languageCodes);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.mosip.kernel.masterdata.dto.request.SearchDto;
import io.mosip.kernel.masterdata.dto.response.FilterResponseCodeDto;
import io.mosip.kernel.masterdata.dto.response.PageResponseDto;
import io.mosip.kernel.masterdata.entity.DynamicField;

/**
* Methods to create / update / inactivate / addValues dynamic field
Expand Down Expand Up @@ -83,4 +82,5 @@ public PageDto<DynamicFieldExtnDto> getAllDynamicField(int pageNumber, int pageS
public DynamicFieldConsolidateResponseDto getDynamicFieldByNameAndLangcode(String fieldName,String langCode,boolean withValue);


List<DynamicFieldExtnDto> getAllDynamicFieldByName(String fieldName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ public interface LocationService {

public FilterResponseCodeDto locFilterValues(FilterValueDto filterValueDto);

LocationResponseDto getImmediateChildrenByLocCode(String locationCode, List<String> languageCodes);
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
package io.mosip.kernel.masterdata.service.impl;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import javax.transaction.Transactional;

import org.json.JSONArray;
import org.json.JSONException;
import io.mosip.kernel.masterdata.dto.response.FilterResult;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.mosip.kernel.core.dataaccess.exception.DataAccessLayerException;
import io.mosip.kernel.masterdata.constant.SchemaErrorCode;
import io.mosip.kernel.masterdata.dto.DynamicFieldConsolidateResponseDto;
Expand All @@ -53,6 +20,7 @@
import io.mosip.kernel.masterdata.dto.request.SearchDto;
import io.mosip.kernel.masterdata.dto.response.ColumnCodeValue;
import io.mosip.kernel.masterdata.dto.response.FilterResponseCodeDto;
import io.mosip.kernel.masterdata.dto.response.FilterResult;
import io.mosip.kernel.masterdata.dto.response.PageResponseDto;
import io.mosip.kernel.masterdata.entity.DynamicField;
import io.mosip.kernel.masterdata.exception.DataNotFoundException;
Expand All @@ -68,20 +36,47 @@
import io.mosip.kernel.masterdata.utils.PageUtils;
import io.mosip.kernel.masterdata.validator.FilterColumnValidator;
import io.mosip.kernel.masterdata.validator.FilterTypeValidator;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.transaction.Transactional;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

@Service
public class DynamicFieldServiceImpl implements DynamicFieldService {

private static final Logger LOGGER = LoggerFactory.getLogger(DynamicFieldServiceImpl.class);

private final ObjectMapper objectMapper = new ObjectMapper();

@Autowired
private DynamicFieldRepository dynamicFieldRepository;

@Autowired
private MasterdataCreationUtil masterdataCreationUtil;

@Autowired
private MasterdataSearchHelper masterdataSearchHelper;

Expand All @@ -99,11 +94,11 @@ public class DynamicFieldServiceImpl implements DynamicFieldService {

@Autowired
AuditUtil auditUtil;


/*
* (non-Javadoc)
*
*
* @see
* io.mosip.kernel.masterdata.service.DynamicFieldService#getAllDynamicField()
*/
Expand All @@ -112,18 +107,18 @@ public class DynamicFieldServiceImpl implements DynamicFieldService {
condition="#langCode != null")
@Override
public PageDto<DynamicFieldExtnDto> getAllDynamicField(int pageNumber, int pageSize, String sortBy, String orderBy, String langCode,
LocalDateTime lastUpdated, LocalDateTime currentTimestamp) {
LocalDateTime lastUpdated, LocalDateTime currentTimestamp) {
Page<Object[]> pagedResult = null;

if (lastUpdated == null) {
lastUpdated = LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC);
}
try {
PageRequest pageRequest = PageRequest.of(pageNumber, pageSize, Sort.by(Direction.fromString(orderBy), sortBy));

PageRequest pageRequest = PageRequest.of(pageNumber, pageSize, Sort.by(Direction.fromString(orderBy), sortBy));
pagedResult = langCode == null ? dynamicFieldRepository.findAllLatestDynamicFieldNames(lastUpdated, currentTimestamp, pageRequest) :
dynamicFieldRepository.findAllLatestDynamicFieldNamesByLangCode(langCode,lastUpdated, currentTimestamp, pageRequest);
dynamicFieldRepository.findAllLatestDynamicFieldNamesByLangCode(langCode,lastUpdated, currentTimestamp, pageRequest);

} catch (DataAccessException | DataAccessLayerException e) {
throw new MasterDataServiceException(SchemaErrorCode.DYNAMIC_FIELD_FETCH_EXCEPTION.getErrorCode(),
SchemaErrorCode.DYNAMIC_FIELD_FETCH_EXCEPTION.getErrorMessage() + " "
Expand All @@ -149,11 +144,11 @@ public PageDto<DynamicFieldExtnDto> getAllDynamicField(int pageNumber, int pageS
list.add(getDynamicFieldDto(groupedValues.get(lang)));
}
});

pagedFields.setPageNo(pagedResult.getNumber());
pagedFields.setTotalPages(pagedResult.getTotalPages());
pagedFields.setTotalItems(pagedResult.getTotalElements());
}
}
return pagedFields;
}

Expand Down Expand Up @@ -204,7 +199,7 @@ public List<DynamicFieldDefDto> getDistinctDynamicFields(String langCode) {

/*
* (non-Javadoc)
*
*
* @see
* io.mosip.kernel.masterdata.service.DynamicFieldService#createDynamicField()
*/
Expand Down Expand Up @@ -241,7 +236,7 @@ public DynamicFieldResponseDto createDynamicField(DynamicFieldDto dto) {

/*
* (non-Javadoc)
*
*
* @see
* io.mosip.kernel.masterdata.service.DynamicFieldService#updateDynamicField()
*/
Expand All @@ -254,10 +249,10 @@ public DynamicFieldResponseDto updateDynamicField(String id, DynamicFieldPutDto

String valueJson = getValidatedFieldValue(dto.getFieldVal());

int updatedRows = dynamicFieldRepository.updateDynamicField(id, dto.getDescription(), dto.getLangCode(),
int updatedRows = dynamicFieldRepository.updateDynamicField(id, dto.getDescription(), dto.getLangCode(),
dto.getDataType(), MetaDataUtils.getCurrentDateTime(), MetaDataUtils.getContextUser(),
valueJson);

if (updatedRows < 1) {
throw new DataNotFoundException(SchemaErrorCode.DYNAMIC_FIELD_NOT_FOUND_EXCEPTION.getErrorCode(),
SchemaErrorCode.DYNAMIC_FIELD_NOT_FOUND_EXCEPTION.getErrorMessage());
Expand All @@ -281,14 +276,14 @@ public StatusResponseDto deleteDynamicFieldValue(String id) {
if(dynamicField == null)
throw new DataNotFoundException(SchemaErrorCode.DYNAMIC_FIELD_NOT_FOUND_EXCEPTION.getErrorCode(),
SchemaErrorCode.DYNAMIC_FIELD_NOT_FOUND_EXCEPTION.getErrorMessage());
if(dynamicField.getValueJson()==null)
throw new DataNotFoundException(SchemaErrorCode.DYNAMIC_FIELD_VALUE_NOT_FOUND_EXCEPTION.getErrorCode(),
if(dynamicField.getValueJson()==null)
throw new DataNotFoundException(SchemaErrorCode.DYNAMIC_FIELD_VALUE_NOT_FOUND_EXCEPTION.getErrorCode(),
SchemaErrorCode.DYNAMIC_FIELD_VALUE_NOT_FOUND_EXCEPTION.getErrorMessage());
JsonNode valueJson =objectMapper.readTree(dynamicField.getValueJson());
String code = valueJson.get("code").toString();



int deletedRows = dynamicFieldRepository.deleteDynamicField(dynamicField.getName(), "%"+code+"%",
MetaDataUtils.getCurrentDateTime(), MetaDataUtils.getContextUser());

Expand Down Expand Up @@ -535,4 +530,29 @@ public DynamicFieldConsolidateResponseDto getDynamicFieldByNameAndLangcode(Strin
}


}
@Override
@Cacheable(value = "dynamic-field", key = "'dynamicfield'.concat('-').concat(#fieldName)")
public List<DynamicFieldExtnDto> getAllDynamicFieldByName(String fieldName) {
List<DynamicField> fields = null;
try {
fields = dynamicFieldRepository.findAllDynamicFieldByName(fieldName);
} catch (DataAccessException | DataAccessLayerException e) {
throw new MasterDataServiceException(SchemaErrorCode.DYNAMIC_FIELD_FETCH_EXCEPTION.getErrorCode(),
SchemaErrorCode.DYNAMIC_FIELD_FETCH_EXCEPTION.getErrorMessage() + " "
+ ExceptionUtils.parseException(e));
}
List<DynamicFieldExtnDto> list = new ArrayList<>();
if(fields != null && !fields.isEmpty()) {
Map<String, List<DynamicField>> groupedValues = fields
.stream()
.collect(Collectors.groupingBy(DynamicField::getLangCode));
list = groupedValues.keySet()
.stream()
.map(lang -> getDynamicFieldDto(groupedValues.get(lang)))
.collect(Collectors.toList());

}
return list;
}

}
Loading

0 comments on commit bd1b078

Please sign in to comment.