Table of Contents |
---|
...
- Please add all your Java classes under PLUGIN_HOME/src/main/java/com/krishagni/openspecimen
- All the Spring configuration should be done in PLUGIN_HOME/src/main/resources/pluginContext.xml
Lets create a plugin to add a custom print token. Below are the steps to follow:
- Create a new project by using the attached skelton
- Import this project into any IDE like eclipse
Add new class
3.1 Add custom token implementation class named SpecimenCollectionProcedurePrintToken.java in package com.krishagni.openspecimen.plugin.token, like below:Code Block package com.krishagni.openspecimen.plugin.token; import com.krishagni.catissueplus.core.biospecimen.domain.Specimen; import com.krishagni.catissueplus.core.common.domain.AbstractLabelTmplToken; import com.krishagni.catissueplus.core.common.domain.LabelTmplToken; public class SpecimenCollectionProcedurePrintToken extends AbstractLabelTmplToken implements LabelTmplToken { @Override public String getName() { return "specimen_collection_procedure"; } @Override public String getReplacement(Object object) { Specimen specimen = (Specimen)object; while (specimen.getParentSpecimen() != null) { specimen = specimen.getParentSpecimen(); } return specimen.getCollectionEvent().getProcedure(); } }
3.2. Add message key for the newly added label token. To add the message key need to update messages.properties file available at PLUGIN_HOME/src/main/resources/errors. Below is the sample: Register the token into OpenSpecimen with LabelTmplTokenRegistrar. Below is the code:
Code Block print_specimen_collection_procedure=Collection Proceudre Note: OpenSpecimen will use this value in the cmd files as the label for collection procedure value.
3.3. Now we need to register the above token into OpenSpecimen with LabelTmplTokenRegistrar. First create a package com.krishagni.openspecimen.plugin.init and write a class named PluginInitializer. This class will register the above token implementation with OpenSpecimen
Code Block package com.krishagni.openspecimen.plugin.init; import org.springframework.beans.factory.InitializingBean; import com.krishagni.catissueplus.core.common.domain.LabelTmplTokenRegistrar; import com.krishagni.openspecimen.plugin.token.SpecimenCollectionProcedurePrintToken; public class PluginInitializer implements InitializingBean { private LabelTmplTokenRegistrar specimenPrintLabelTokensRegistrar; public void setSpecimenPrintLabelTokensRegistrar(LabelTmplTokenRegistrar specimenPrintLabelTokensRegistrar) { this.specimenPrintLabelTokensRegistrar = specimenPrintLabelTokensRegistrar; } @Override public void afterPropertiesSet() throws Exception { specimenPrintLabelTokensRegistrar.register(new SpecimenCollectionProcedurePrintToken()); } }
3.4. We have created a custom class for the token and written a plugin initializer which will register the new token with the LabelTmplTokenRegistrar. To make Spring aware to load this class we need to update the spring context. For this we need to add below in file PLUGIN_HOME/src/main/resources/pluginContext.xml
Code Block <bean id="pluginInitializer" class="com.krishagni.openspecimen.plugin.init.PluginInitializer"> <property name="specimenPrintLabelTokensRegistrar" ref="specimenPrintLabelTokensRegistrar"/> </bean>
Steps to create plugin archive
The build system uses Gradle to manage code compilation, building plugin jar archive.
...