Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@Slf4j
public class SequentialReceiptNumberGenerator implements IReceiptNumberGenerator {

private final ISequentialReceiptNumberGeneratorService service;
private final SequentialReceiptNumberGeneratorService service;

private SequentialReceiptNumberGeneratorModel model;

Expand All @@ -36,7 +36,7 @@ public class SequentialReceiptNumberGenerator implements IReceiptNumberGenerator
private boolean loaded = false;

public SequentialReceiptNumberGenerator() {
service = Context.getService(ISequentialReceiptNumberGeneratorService.class);
service = Context.getService(SequentialReceiptNumberGeneratorService.class);
checkDigitGenerator = new LuhnIdentifierValidator();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import java.util.List;

import org.openmrs.module.billing.api.base.entity.IObjectDataService;
import org.openmrs.api.OpenmrsService;
import org.openmrs.module.billing.api.model.GroupSequence;
import org.openmrs.module.billing.api.model.SequentialReceiptNumberGeneratorModel;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -21,7 +21,7 @@
* {@link SequentialReceiptNumberGeneratorModel}. The {@link SequentialReceiptNumberGeneratorModel}
* model class.
*/
public interface ISequentialReceiptNumberGeneratorService extends IObjectDataService<SequentialReceiptNumberGeneratorModel> {
public interface SequentialReceiptNumberGeneratorService extends OpenmrsService {

/**
* Gets the first {@link SequentialReceiptNumberGeneratorModel} or creates a new model if none have
Expand All @@ -31,8 +31,21 @@ public interface ISequentialReceiptNumberGeneratorService extends IObjectDataSer
* @should return the first model.
* @should return a new model if none has been defined.
*/
@Transactional(readOnly = true)
SequentialReceiptNumberGeneratorModel getOnly();

/**
* Saves the {@link SequentialReceiptNumberGeneratorModel}, creating a new one or updating an
* existing one.
*
* @param model The model to save.
* @return The saved model.
* @throws IllegalArgumentException if model is null
* @should save the model successfully
*/
@Transactional
SequentialReceiptNumberGeneratorModel save(SequentialReceiptNumberGeneratorModel model);

/**
* Reserves the next sequence value for the specified group.
*
Expand Down Expand Up @@ -73,7 +86,7 @@ public interface ISequentialReceiptNumberGeneratorService extends IObjectDataSer
*
* @param sequence The sequence to save.
* @return The saved sequence.
* @should Throw a NullPointerException if sequence is null
* @should Throw an IllegalArgumentException if sequence is null
* @should return the saved sequence
* @should update the sequence successfully
* @should create the sequence successfully
Expand All @@ -85,7 +98,7 @@ public interface ISequentialReceiptNumberGeneratorService extends IObjectDataSer
* Complete removes the specified sequence from the database.
*
* @param sequence The sequence to remove.
* @should Throw a NullPointerException if the sequence is null
* @should Throw an IllegalArgumentException if the sequence is null
* @should delete the sequence from the database
* @should not throw an exception if the sequence is not in the database
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,29 @@

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.openmrs.module.billing.api.ISequentialReceiptNumberGeneratorService;
import org.openmrs.module.billing.api.base.entity.impl.BaseObjectDataServiceImpl;
import org.openmrs.api.impl.BaseOpenmrsService;
import org.openmrs.module.billing.api.SequentialReceiptNumberGeneratorService;
import org.openmrs.module.billing.api.base.entity.db.hibernate.BaseHibernateRepository;
import org.openmrs.module.billing.api.model.GroupSequence;
import org.openmrs.module.billing.api.model.SequentialReceiptNumberGeneratorModel;
import org.openmrs.module.billing.api.security.BasicEntityAuthorizationPrivileges;
import org.springframework.transaction.annotation.Transactional;

/**
* Data service implementation class for {@link SequentialReceiptNumberGeneratorModel}s.
*/
@Transactional
public class SequentialReceiptNumberGeneratorServiceImpl extends BaseObjectDataServiceImpl<SequentialReceiptNumberGeneratorModel, BasicEntityAuthorizationPrivileges> implements ISequentialReceiptNumberGeneratorService {
public class SequentialReceiptNumberGeneratorServiceImpl extends BaseOpenmrsService implements SequentialReceiptNumberGeneratorService {

@Override
protected BasicEntityAuthorizationPrivileges getPrivileges() {
// No authorization required
return null;
}
private BaseHibernateRepository repository;

@Override
protected void validate(SequentialReceiptNumberGeneratorModel entity) {
public void setRepository(BaseHibernateRepository repository) {
this.repository = repository;
}

@Override
@Transactional(readOnly = true)
public SequentialReceiptNumberGeneratorModel getOnly() {
List<SequentialReceiptNumberGeneratorModel> records = getAll();
List<SequentialReceiptNumberGeneratorModel> records = repository.select(SequentialReceiptNumberGeneratorModel.class);

if (!records.isEmpty()) {
return records.get(0);
Expand All @@ -48,6 +44,15 @@ public SequentialReceiptNumberGeneratorModel getOnly() {
}
}

@Override
@Transactional
public SequentialReceiptNumberGeneratorModel save(SequentialReceiptNumberGeneratorModel model) {
if (model == null) {
throw new IllegalArgumentException("The model to save must be defined.");
}
return repository.save(model);
}

@Override
@Transactional
public int reserveNextSequence(String group) {
Expand All @@ -73,7 +78,7 @@ public int reserveNextSequence(String group) {
@Override
@Transactional(readOnly = true)
public List<GroupSequence> getSequences() {
return getRepository().select(GroupSequence.class);
return repository.select(GroupSequence.class);
}

@Override
Expand All @@ -83,29 +88,30 @@ public GroupSequence getSequence(String group) {
throw new IllegalArgumentException("The group must be defined.");
}

Criteria criteria = getRepository().createCriteria(GroupSequence.class);
Criteria criteria = repository.createCriteria(GroupSequence.class);
criteria.add(Restrictions.eq("group", group));

return getRepository().selectSingle(GroupSequence.class, criteria);
return repository.selectSingle(GroupSequence.class, criteria);
}

@Override
@Transactional
public GroupSequence saveSequence(GroupSequence sequence) {
if (sequence == null) {
throw new NullPointerException("The sequence to save must be defined.");
throw new IllegalArgumentException("The sequence to save must be defined.");
}

return getRepository().save(sequence);
return repository.save(sequence);
}

@Override
@Transactional
public void purgeSequence(GroupSequence sequence) {
if (sequence == null) {
throw new NullPointerException("The sequence to purge must be defined.");
throw new IllegalArgumentException("The sequence to purge must be defined.");
}

getRepository().delete(sequence);
repository.delete(sequence);
}

}
5 changes: 2 additions & 3 deletions api/src/main/resources/moduleApplicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<bean parent="serviceContext">
<property name="moduleService">
<list merge="true">
<value>org.openmrs.module.billing.api.ISequentialReceiptNumberGeneratorService</value>
<value>org.openmrs.module.billing.api.SequentialReceiptNumberGeneratorService</value>
<ref bean="seqReceiptNumberGeneratorService"/>
</list>
</property>
Expand Down Expand Up @@ -182,8 +182,7 @@
<property name="preInterceptors" ref="serviceInterceptors"/>
<property name="transactionAttributeSource" ref="transactionAttributeSource"/>
</bean>
<bean id="seqReceiptNumberGeneratorService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<bean id="seqReceiptNumberGeneratorService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target">
<bean class="org.openmrs.module.billing.api.impl.SequentialReceiptNumberGeneratorServiceImpl">
Expand Down
Loading