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

Support additional metadata processing when publishing / un-publishing metadata. #7747

Merged
merged 4 commits into from
Apr 23, 2024

Conversation

josegar74
Copy link
Member

@josegar74 josegar74 commented Feb 13, 2024

Follow up of #7148

The change adds a method processMetadata with an empty implementation to the IPublicationConfig interface that can be implemented by a custom publication configuration to execute additional processing on the metadata published / unpublished, for example to assign / remove a category:

public class CustomPublicationConfig extends DefaultPublicationConfig {

    @PostConstruct
    @Override
    public void init() {
        // Define the publication options
        ...
       
    }

    @Override
    public void processMetadata(ServiceContext serviceContext, PublicationOption publicationOption, 
                                Integer metadataId, boolean publish) throws Exception {
        // Check the publication option used 
        if (!publicationOption.getName().equals("publishAndSetCategory")) return;

        MetadataCategoryRepository metadataCategoryRepository = serviceContext.getBean(MetadataCategoryRepository.class);
        IMetadataCategory metadataCategory = serviceContext.getBean(IMetadataCategory.class);
        IMetadataIndexer metadataIndexer = serviceContext.getBean(IMetadataIndexer.class);
        MetadataCategory category = metadataCategoryRepository.findOneByName("CUSTOMCATEGORY");
        if (category == null) return;

        boolean hasCategory = metadataCategory.isCategorySet(String.valueOf(metadataId), category.getId());
        boolean updatedCategory = false;

        if (publish) {
            if (!hasCategory) {
                metadataCategory.setCategory(serviceContext, String.valueOf(metadataId), String.valueOf(category.getId()));
                updatedCategory = true;
            }
        } else {
            if (hasCategory) {
                metadataCategory.unsetCategory(serviceContext, String.valueOf(metadataId), category.getId());
                updatedCategory = true;
            }
        }

        if (updatedCategory) {
            metadataIndexer. indexMetadata(String.valueOf(metadataId), true, IndexingMode.full);
        }
    }

The default publication configuration (https://github.com/geonetwork/core-geonetwork/blob/main/services/src/main/java/org/fao/geonet/config/DefaultPublicationConfig.java) is not changed.

Also adds a class name in the user interface to facilitate the styling of the publication options in the Manage record menu.

Checklist

  • I have read the contribution guidelines
  • Pull request provided for main branch, backports managed with label
  • Good housekeeping of code, cleaning up comments, tests, and documentation
  • Clean commit history broken into understandable chucks, avoiding big commits with hundreds of files, cautious of reformatting and whitespace changes
  • Clean commit messages, longer verbose messages are encouraged
  • API Changes are identified in commit messages
  • Testing provided for features or enhancements using automatic tests
  • User documentation provided for new features or enhancements in manual
  • Build documentation provided for development instructions in README.md files
  • Library management using pom.xml dependency management. Update build documentation with intended library use and library tutorials or documentation

@josegar74 josegar74 added this to the 4.4.3 milestone Feb 13, 2024
@josegar74 josegar74 requested a review from fxprunayre February 13, 2024 12:16
@josegar74 josegar74 force-pushed the 44-publicationoptions-processing branch from 63cfe2e to fffd513 Compare February 13, 2024 12:29
@josegar74 josegar74 changed the title Support additional metadata procession when publishing / un-publishing metadata. Support additional metadata processing when publishing / un-publishing metadata. Feb 13, 2024
@ianwallen
Copy link
Contributor

It seems odd to create a new interface IPublicationAction instead of adding the processMetadata() to the existing IPublicationConfig interface? Then DefaultPublicationConfig would default to processMetadata() doing nothing.

This would remove all the instanceOf checks.

And then if someone wants to add functionality for processMetadata() they could just extend the DefaultPublicationConfig.

public class CustomPublicationConfig extends DefaultPublicationConfig

@josegar74
Copy link
Member Author

@ianwallen the idea was to avoid the processing of the metadata in batch publication, even if the method does nothing, but I can update the code with your suggestions.

…nAction interface. Fix the batch sharing report not filling the metadata processed list
@josegar74 josegar74 force-pushed the 44-publicationoptions-processing branch from 156ae54 to a73041f Compare February 20, 2024 10:45
@josegar74
Copy link
Member Author

@ianwallen I've updated the code from your suggestions, updating the method to accept the metadata identifier, so doesn't need to be retrieved in advance the metadata instance, specially for batch processing.

Also fixed the batch sharing report not filling properly the list of metadata processed.

@fxprunayre fxprunayre modified the milestones: 4.4.3, 4.4.4 Mar 13, 2024
@fxprunayre fxprunayre modified the milestones: 4.4.4, 4.4.5 Apr 16, 2024
Copy link
Contributor

@ianwallen ianwallen left a comment

Choose a reason for hiding this comment

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

Tested and seems to work as expected.

@josegar74 josegar74 merged commit 5f86440 into geonetwork:main Apr 23, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants