Skip to content

Commit

Permalink
refactored the code
Browse files Browse the repository at this point in the history
  • Loading branch information
shijinrajbosch committed Oct 9, 2023
1 parent 5b66150 commit 69e822b
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ private void checkForDuplicateIdShortWithInSubModels( Shell shell ) {
.map( String::toLowerCase )
.toList();

Optional.of( idShortList ).filter( idShorts -> idShortList.stream().distinct().count() == idShorts.size() ) // checking for duplicate idShort
.orElseThrow( () -> new DuplicateKeyException( DUPLICATE_SUBMODEL_EXCEPTION ) );
boolean isDuplicateIdShortPresent = Optional.of( idShortList ).filter( idShorts -> idShortList.stream().distinct().count() != idShorts.size() )
.isPresent();

if ( isDuplicateIdShortPresent ) {
throw new DuplicateKeyException( DUPLICATE_SUBMODEL_EXCEPTION );
}

}

public void mapShellCollection(Shell shell){
Expand Down Expand Up @@ -359,11 +364,9 @@ public Submodel save( String externalShellId, Submodel submodel, String external
.anyMatch(
idShort -> idShort.toLowerCase().equals( submodel.getIdShort().toLowerCase() ) ); // check whether the input sub-model.idShort exists in DB

Optional.of( isIdShortPresent ).filter( BooleanUtils::isFalse )
.orElseThrow( () -> new DuplicateKeyException(
DUPLICATE_SUBMODEL_EXCEPTION ) );// Throw exception if sub-model.idShort exists in DB


if(isIdShortPresent){// Throw exception if sub-model.idShort exists in DB
throw new DuplicateKeyException(DUPLICATE_SUBMODEL_EXCEPTION);
}
return saveSubmodel( submodel );
}

Expand Down

0 comments on commit 69e822b

Please sign in to comment.