Skip to content

Commit

Permalink
Mosip 26350 fix share cred req (#802)
Browse files Browse the repository at this point in the history
* Fix for setting read status to false

* Revert "Fix for setting read status to false (#791)"

This reverts commit c00a051.

* Check test fix

* Fix NPE in test in github

* Test fix

* logic fix in test

* Test fix

* Test fix

* Minor fixes

* Ignoring test for build failure in github action. to be reverted and fixed

* Fix for setting read status to false (#791)

Co-authored-by: Loganathan Sekar <[email protected]>

* Fix for share credential request to cred req service

* fix for is masked false

* Fix for isMasked

---------

Co-authored-by: Loganathan Sekar <[email protected]>
  • Loading branch information
loganathan-sekaran and Loganathan Sekar authored Mar 14, 2023
1 parent f2d7dc5 commit c692950
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.mosip.resident.dto.ResidentCredentialRequestDto;
import io.mosip.resident.dto.ResidentCredentialResponseDto;
import io.mosip.resident.dto.ResidentCredentialResponseDtoV2;
import io.mosip.resident.dto.SharableAttributesDTO;
import io.mosip.resident.dto.ShareCredentialRequestDto;
import io.mosip.resident.exception.ApisResourceAccessException;
import io.mosip.resident.exception.ResidentServiceCheckedException;
Expand Down Expand Up @@ -221,11 +222,17 @@ private void buildAdditionalMetadata(RequestWrapper<ShareCredentialRequestDto> r
requestDTO.getRequest().getSharableAttributes(), UISchemaTypes.SHARE_CREDENTIAL.getFileIdentifier());
if (Objects.nonNull(requestDTO.getRequest().getSharableAttributes())) {
request.getRequest().setSharableAttributes(sharableAttr);
Map<String, String> formattingAttributes = requestDTO.getRequest().getSharableAttributes()
.stream()
.filter(attrib -> attrib.getFormat() != null && !attrib.getFormat().isEmpty())
.collect(Collectors.toMap(SharableAttributesDTO::getAttributeName, SharableAttributesDTO::getFormat));
request.getRequest()
.setAdditionalData(Map.of("formatingAttributes", requestDTO.getRequest().getSharableAttributes(),
.setAdditionalData(Map.of("formatingAttributes", formattingAttributes,
"maskingAttributes",
requestDTO.getRequest().getSharableAttributes().stream().filter(attr -> attr.isMasked())
.map(attr -> attr.getAttributeName()).collect(Collectors.toList())));
requestDTO.getRequest().getSharableAttributes().stream()
.filter(attr -> attr.isMasked())
.map(attr -> attr.getAttributeName())
.collect(Collectors.toList())));

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.mosip.resident.dto;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;

/**
Expand All @@ -13,5 +15,6 @@ public class SharableAttributesDTO {

private String format;

@JsonProperty("isMasked")
private boolean isMasked;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
@Component
public class ResidentConfigServiceImpl implements ResidentConfigService {

private static final String VALUE = "value";

private static final String UI_SCHEMA_ATTRIBUTE_NAME = "mosip.resident.schema.attribute-name";

private static final String CONTROL_TYPE = "controlType";
Expand Down Expand Up @@ -189,24 +191,24 @@ public List<String> getSharableAttributesList(List<SharableAttributesDTO> sharab
List<String> idsListFromUISchema = identityList.stream().map(map -> String.valueOf(map.get(env.getProperty(UI_SCHEMA_ATTRIBUTE_NAME))))
.collect(Collectors.toList());

// attribute list from format present in both identity-mapping & ui-schema json
List<String> sharableList1 = sharableAttrList.stream()
.filter(map -> identityMap.containsKey(map.getAttributeName()) && map.getFormat()!=null)
.flatMap(attr -> Stream.of(attr.getFormat().split(",")))
.filter(idsListFromUISchema::contains)
.collect(Collectors.toList());

// attribute list from format not present in identity-mapping & but in ui-schema json
List<String> sharableList2 = sharableAttrList.stream()
.filter(map -> !identityMap.containsKey(map.getAttributeName()) && map.getFormat()!=null)
.map(map -> map.getFormat())
List<String> shareableAttributes = sharableAttrList.stream()
.flatMap(attribute -> {
// Get the attributes from the format if specified
if(attribute.getFormat()!=null && !attribute.getFormat().isEmpty()) {
return Stream.of(attribute.getFormat().split(","));
}
// Get the attributes from the identity mapping
if(identityMap.containsKey(attribute.getAttributeName())) {
return Stream.of(String.valueOf(((Map) identityMap.get(attribute.getAttributeName())).get(VALUE))
.split(","));
}
// Return the attribute name itself
return Stream.of(attribute.getAttributeName());
})
.filter(idsListFromUISchema::contains)
.collect(Collectors.toList());

return Stream.of(sharableList1, sharableList2)
.flatMap(x -> x.stream())
.distinct()
.collect(Collectors.toList());
return shareableAttributes;
}

}

0 comments on commit c692950

Please sign in to comment.