Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRUNK-6304 Refactor code to use Storage Service #4944

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rkorytkowski
Copy link
Member

Description of what I changed

Issue I worked on

see https://issues.openmrs.org/browse/TRUNK-

Checklist: I completed these to help reviewers :)

  • [ x] My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • [ x] I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • [x ] I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute above command

  • [x ] All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • [x ] My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

@rkorytkowski
Copy link
Member Author

It contains changes from both TRUNK-6300 and TRUNK-6304. They are in separate commits as I'm hoping to backport TRUNK-6300.

@rkorytkowski rkorytkowski changed the title Trunk 6304 TRUNK-6304 Refactor code to use Storage Service Feb 26, 2025
File complexObsDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(adminService
.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR));
File createdFile = createImage(complexObsDir, "openmrs_logo_small.gif");

Obs complexObs = obsService.getComplexObs(44, ComplexObsHandler.RAW_VIEW);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getCompexObs failed due to missing file with a new implementation. It appears that the old implementation didn't complain that the file didn't exist. I'm confused whether we should fail if the file is missing or silently ignore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkayiwa @ibacher do you have any opinion about that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to reduce the possibility of unintended side effects of introducing a new storage service, i would preserve the existing behaviour. Then if we need to change it to fail if the file is missing, i would do that as a separate ticket and pull request. 😊

@dkayiwa dkayiwa requested a review from wikumChamith February 27, 2025 09:13

private final MimetypesFileTypeMap mimetypes = new MimetypesFileTypeMap();

public LocalStorageService(@Value("${storage_dir}") String storageDir, @Autowired StreamDataService streamService) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we define the storage_dir? Do we have a property source?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have a property source properly configured in openmrs-core. In such a case the way to define it is to use environment or system variable storage_dir. It's a typical Docker approach of configuring an app.

We probably want to configure property source from openmrs-runtime.properties, but that deserves a separate issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we use @Value("${storage_dir}") after implementing that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would first use value from the env property if not found try sys property and finally openmrs-runtime.properties. See also https://docs.spring.io/spring-boot/docs/2.6.1/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding

@@ -36,6 +43,12 @@ public class AbstractHandler {

protected NumberFormat nf;

@Autowired
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason for keeping these access modifiers as default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default lets us easily mock them in tests that we put in the same package. I included them in a constructor so it's not needed in this case, but sometimes constructor would be too long. I don't know if we have a convention around that, but it's something I find quite common in spring code. They could be protected as well, but then mocking is only feasible via the constructor.

@rkorytkowski rkorytkowski marked this pull request as ready for review February 28, 2025 09:46
@rkorytkowski
Copy link
Member Author

It's no longer a draft. There's one final question I have around failing if file is missing. See above. Other than that I consider it ready. #4920 should be merged first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants