admin管理员组

文章数量:1415652

I have very crucial encrytion decrytion file and getting this Sonar warning

Make the enclosing method "static" or remove this set

Now, because variables are static, the method in which their values are setting should be static, but we are also autowiring them, and static methods cannot be autowired

And if I make the variable non-static, then I get this error

An unexpected error occurred: Error occurred while patient update. Cannot invoke "com.docasap.patientmanagementservice.helpers.EncryptDecryptHelper.buildEncryptDecryptServiceImpl()" because "this.encryptDecryptHelper" is null

@Slf4j
@Component
public class StudentEventListener {

    private static OptStudentRepo optStudentRepo;
    private static IntStudentRepo intStudentRepo;
    private static EncryptDecryptHelper encryptDecryptHelper;

    @Autowired
    public void setEncryptDecryptHelper(EncryptDecryptHelper encryptDecryptHelp) {
        encryptDecryptHelper = encryptDecryptHelp;
    }

    @Autowired
    public void setOasPatientRepo(IntStudentRepo intStudentRepo1) {
        intStudentRepo = intStudentRepo1;
    }

    @Autowired
    public void setOrgPatientRepo(OptStudentRepo optStudentRepo1) {
        optStudentRepo = optStudentRepo1;
    }

    protected EncryptDecryptService determineEncryptionKey(StudentRecord sr) {
        HashMap<String, Integer> encIds = sr.getEncryptionIds(intStudentRepo, optStudentRepo);
        EncryptDecryptService encryptDecryptService = encryptDecryptHelper.buildEncryptDecryptServiceImpl();
        try {
           
            encryptDecryptService.setValue(encIds.get("schoolId").toString(), encIds.get("classId"), SupportedEncryption.AES256);
            return encryptDecryptService;
        } catch (InvalidPropertiesFormatException | RuntimeException e) {
            try {
                encryptDecryptService.setValue("0", 0, SupportedEncryption.AES256);
                return encryptDecryptService;
            } catch (InvalidPropertiesFormatException ex) {
                throw new RuntimeException(ex);
            }
        }
       
    }
}

This class is being extended in several other classes where we are making records encrypted or decrypted

@Slf4j
@Component
public class OptStudentEventListener extends StudentEventListener {

    @PrePersist
    public void encryptRecord(OptStudent os) throws Throwable {
        if (os.getIsEncrypted()) {
            return;
        }
        EncryptDecryptService encryptDecryptService = determineEncryptionKey(os);
        os.setFirstName(encryptDecryptService.encryptString(pc.getFirstName()));
        os.setLastName(encryptDecryptService.encryptString(pc.getLastName()));
        os.setMiddleName(encryptDecryptService.encryptString(pc.getMiddleName()));
        os.setIsEncrypted(true);
    }
}

How can I make this work without Sonar warnings?

本文标签: