Comments (3)
By looking into #77 (comment)
Imaging having a func
with assign-output
s and no calculation
annotation.
Where should the code for assign-outputs be generated?
from rune-dsl.
After our discussions this afternoon, here is the java code that I think we should generate. A few points to note:
- doEvaluate is a protected abstract method, which should be overridden by the implementor
- the assign-output logic is moved into a private method that returns a Builder object that is subsequently used to evaluate post-conditions
- The default implementation should return an empty builder object instead of an exception. From making use of the Functions, it was annoying to have to create no-op implementations of every function.
- post-conditions to remain where they are currently in the
evaluate
method, to be placed after theassignOutput
call and beforeobjectValidator.validateAndFailOnErorr(...)
@ImplementedBy(ResolveEquityContract.ResolveEquityContractDefault.class)
public abstract class ResolveEquityContract implements RosettaFunction {
@Inject protected ModelObjectValidator objectValidator;
// RosettaFunction dependencies
@Inject protected CalculationPeriod calculationPeriod;
@Inject protected EquityPerformance equityPerformance;
/**
* @param contractState
* @param observation
* @param date
* @return updatedContract
*/
public Contract evaluate(ContractState contractState, ObservationPrimitive observation, Date date) {
// pre-conditions
assert
exists(MapperS.of(equityPayout(contractState, observation, date).get()), false).get()
: "";
ContractBuilder updatedContractHolder = doEvaluate(contractState, observation, date);
// assign-output
Contract assignedUpdatedContract = assignOutput(updatedContractHolder, contractState, observation, date).build();
objectValidator.validateAndFailOnErorr(Contract.class, assignedUpdatedContract);
return assignedUpdatedContract;
}
protected abstract ContractBuilder doEvaluate(ContractState contractState, ObservationPrimitive observation, Date date);
private ContractBuilder assignOutput(ContractBuilder updatedContractHolder, ContractState contractState, ObservationPrimitive observation, Date date) {
updatedEquityPayout(updatedContractHolder, contractState, observation, date)
.getOrCreatePriceReturnTerms().getOrCreateValuationPriceFinal().getOrCreateNetPrice()
.setAmount(doIf(MapperS.of(calculationPeriod.evaluate(MapperS.of(equityPayout(contractState, observation, date).get()).<CalculationPeriodDates>map("getCalculationPeriodDates", EquityPayout::getCalculationPeriodDates).get(), MapperS.of(periodEndDate(contractState, observation, date).get()).get())).<Boolean>map("getIsLastPeriod", CalculationPeriodData::getIsLastPeriod),MapperS.of(price(contractState, observation, date).get())).get());
updatedEquityPayout(updatedContractHolder, contractState, observation, date)
.getOrCreatePriceReturnTerms().getOrCreateValuationPriceInterim().getOrCreateNetPrice()
.setAmount(doIf(areEqual(MapperS.of(calculationPeriod.evaluate(MapperS.of(equityPayout(contractState, observation, date).get()).<CalculationPeriodDates>map("getCalculationPeriodDates", EquityPayout::getCalculationPeriodDates).get(), MapperS.of(periodEndDate(contractState, observation, date).get()).get())).<Boolean>map("getIsLastPeriod", CalculationPeriodData::getIsLastPeriod), MapperS.of(Boolean.valueOf(false))),MapperS.of(price(contractState, observation, date).get())).get());
updatedContractHolder
.getOrCreateContractualProduct().getOrCreateEconomicTerms().getOrCreatePayout().getOrCreateEquityPayout(0)
.setPerformance(MapperS.of(equityPerformance(contractState, observation, date).get()).get());
updatedContractHolder
.getOrCreateContractualProduct().getOrCreateEconomicTerms().getOrCreatePayout().getOrCreateEquityPayout(0).getOrCreatePayoutQuantity().getOrCreateQuantityMultiplier()
.setMultiplierValue(MapperMaths.<BigDecimal, Integer, BigDecimal>add(MapperS.of(Integer.valueOf(1)), MapperMaths.<BigDecimal, BigDecimal, Integer>divide(MapperS.of(equityPerformance(contractState, observation, date).get()), MapperS.of(Integer.valueOf(100)))).get());
return updatedContractHolder;
}
public static final class ResolveEquityContractDefault extends ResolveEquityContract {
@Override
protected ContractBuilder doEvaluate(ContractState contractState, ObservationPrimitive observation, Date date) {
return Contract.builder();
}
}
// Alias's
...
from rune-dsl.
@jim-h-wang
Disabled two tests because in doEvaluate we now have an empty object created by the builder.
from rune-dsl.
Related Issues (20)
- Rename master to main HOT 2
- Create Docusaurus website basic structure HOT 3
- Static compilation error when type starts with lowercase character
- Enhancements to one-of construct HOT 26
- Unable to build the repo HOT 5
- Xtext grammar file is too large HOT 1
- Condition with only exists operator should only validate attributes on the type that contains the condition
- Errors in naming of Rune DSL in documentation HOT 1
- DSL should show when the implementation of a function is in code (ie Java) HOT 3
- Clarification of the definition and use of the meta data annotations HOT 4
- Missing documentation on the generated Java code
- Incompatible Types error thrown converting List of String(Enum Value) to List of FieldWithMetaString
- Caching sometimes breaks change propagation
- Highlighting broken for `only exists` and `required choice` with a comma
- Code generator crashes when using Java keyword `exists` in Function output
- Using fully qualified name of enum in expression returns class cast error
- Tabulator Generator does not support circular dependancies
- Dedicated choice types
- Support choice types as enum
- Choice type attributes should be referencable with address/location
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rune-dsl.