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 5d10879 commit 5b66150
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
@Service
public class ShellService {

private final String AN_ASSET_ADMINISTRATION_SUBMODEL_FOR_THE_GIVEN_IDENTIFICATION_DOES_ALREADY_EXISTS = "An AssetAdministrationSubmodel for the given identification does already exists.";
public static final String DUPLICATE_SUBMODEL_EXCEPTION = "An AssetAdministrationSubmodel for the given identification does already exists.";

private final ShellRepository shellRepository;
private final ShellIdentifierRepository shellIdentifierRepository;
Expand Down Expand Up @@ -124,7 +124,7 @@ private void checkForDuplicateIdShortWithInSubModels( Shell shell ) {
.toList();

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

public void mapShellCollection(Shell shell){
Expand Down Expand Up @@ -361,15 +361,15 @@ public Submodel save( String externalShellId, Submodel submodel, String external

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


return saveSubmodel( submodel );
}

public Submodel saveSubmodel(Submodel submodel){
if(submodelRepository.findByShellIdAndIdExternal(submodel.getShellId(),submodel.getIdExternal()).isPresent()){
throw new DuplicateKeyException( AN_ASSET_ADMINISTRATION_SUBMODEL_FOR_THE_GIVEN_IDENTIFICATION_DOES_ALREADY_EXISTS );
throw new DuplicateKeyException( DUPLICATE_SUBMODEL_EXCEPTION );
}
return submodelRepository.save( submodel );
}
Expand Down

0 comments on commit 5b66150

Please sign in to comment.