Created
September 7, 2012 14:11
-
-
Save mkubala/3666560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface AlgorithmService { | |
boolean isApplicableFor(final MrpAlgorithm algorothm); | |
Map<Entity, BigDecimal> perform(final Map<Entity, BigDecimal> productComponentQuantities, final Set<Entity> nonComponents, | |
final MrpAlgorithm algorithm, final String type); | |
} | |
--------------------------------------------- | |
@Service | |
public class ConcreteAlgorithmService implements AlgorithmService { | |
@Override | |
public boolean isApplicableFor(final MrpAlgorithm algorothm) { | |
return MrpAlgorithm.COSTAM.equals(algorithm); | |
} | |
@Override | |
public Map<Entity, BigDecimal> perform(Map<Entity, BigDecimal> productComponentQuantities, Set<Entity> nonComponents) { | |
// specific ProductQuantitiesServiceImpl.getProducts overriding implemnetation here | |
return ..; | |
} | |
} | |
------------------------------------------- | |
@Aspect | |
public abstract class AbstractAlgorithmResolverAspect { | |
protected abstract AlgorithmService getAlgorithmService(); | |
@Pointcut("execution(private Map<Entity, BigDecimal> com.qcadoo.mes.technologies.ProductQuantitiesServiceImpl.getProducts(..)) " | |
+ "&& args(productComponentQuantities,nonComponents, algorithm, type)") | |
public void getProductsMethodExecution(final Map<Entity, BigDecimal> productComponentQuantities, | |
final Set<Entity> nonComponents, final MrpAlgorithm algorithm, final String type) { | |
} | |
@Around("getProductsMethodExecution(productComponentQuantities,nonComponents, algorithm, type)") | |
public Map<Entity, BigDecimal> aroundGetProductsMethodExecution(final ProceedingJoinPoint pjp, final Map<Entity, BigDecimal> productComponentQuantities, final Set<Entity> nonComponents, final MrpAlgorithm algorithm, final String type) throws Throwable { | |
if (getAlgorithmService().isApplicableFor(algorithm)) { | |
getAlgorithmService().perform(productComponentQuantities, nonComponents ...); | |
} else { | |
pjp.proceed(); | |
} | |
} | |
} | |
----------------------------------------------- | |
@Aspect | |
@RunIfEnabled("techSubcontractors") | |
public final class ConcreteAlgorithmResolverAspect extends AbstractAlgorithmResolverAspect { | |
@Autowired | |
private AlgorithmService concreAlgorithmService; | |
protected AlgorithmService getAlgorithmService() { | |
return concreAlgorithmService; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment