Re: M:N association refuses to work

2017-04-30 Thread Dan Haywood
Did you resolve this, Eder?

If not, could you put together an example application in github
demonstrating the issue?

Thx
Dan

On Thu, 6 Apr 2017 at 17:22 L Eder  wrote:

> Correcting this ...
>
> ResultRepository.java
> "
> public class ResultRepository {
>
> @Programmatic
> public Result create(
> final String description,
> final int simulationYear,
> final int status
> ) {
> final Result result =
> container.newTransientInstance(Result.class);
>
> result.setDescription(description);
> result.setSimulationYear(simulationYear);
> result.setStatus(status);
> return result;
> }
> }
> "
>
>
> 2017-04-06 12:20 GMT-04:00, L Eder :
> > Hi members of this forum:
> >
> > I have this situation - a Scenario entity comprised of many Result
> > entities. And vice-versa.
> >
> > I then add the first result to a sortedset, using Scenario.runScenario().
> >
> > However when i add the second result object, in
> > Scenario.adjustResult(), the first one is overwritten.
> >
> > Thanks for any help on this issue, Eder
> >
> > ---
> >
> > Scenario.java
> > "
> > public class Scenario implements Comparable {
> >
> > public String title() {
> > return getDescription();
> > }
> >
> > @Column(allowsNull = "false")
> > @Property()
> > @Getter @Setter
> > private String description;
> >
> > @Column(allowsNull = "false")
> > @Property()
> > @Getter
> > @Setter
> > private int simulationYear;
> >
> > @Column(allowsNull = "false")
> > @Property()
> > @Getter @Setter
> > private ModelCategory modelCategory;
> >
> > //@Property(hidden = Where.ANYWHERE)
> > @Column(allowsNull = "true")
> > @Property()
> > @Getter @Setter
> > private Result budget;
> >
> > @Persistent(table = "ScenarioResults")
> > @Join(column = "scenario_id")
> > //@Element(column = "res_id")
> > @Element(column = "result_id")
> > @Collection()
> > @Getter @Setter
> > @CollectionLayout(render = RenderType.EAGERLY)
> > private SortedSet actuals = new TreeSet();
> >
> > 
> > public Scenario importSeihan(
> > @Parameter(fileAccept = ".xlsx")
> > @ParameterLayout(named="Excel spreadsheet")
> > final Blob spreadsheet){
> > 
> > getBudget().getCords().add(qitem);
> > 
> > }
> >
> > @Action()
> > public Result runScenario(){
> >
> > getActuals().add(getBudget());
> >
> > return getBudget();
> > }
> >
> > @Action()
> > public Result adjustResult() {
> > Date dNow = new Date();
> > SimpleDateFormat ft =
> > new SimpleDateFormat ("dd---HH:mm");
> >
> > /*final*/ Result adj = getBudget();
> > String descr = getDescription() + "_adjust_" + ft.format(dNow)
> > + "_[optional description]";
> > adj.setDescription(descr);
> > adj.setStatus(AdjustStatus.valueOf("InProgress").ordinal());
> >
> > getActuals().add(adj);
> >
> > return resultRepo.findByDescription(descr);
> > }
> >
> >
> > @Override
> > public int compareTo(final Scenario other) {
> > return org.apache.isis.applib.util.ObjectContracts.compare(this,
> > other, "description");
> > }
> >
> > @Override
> > public String toString() {
> > return org.apache.isis.applib.util.ObjectContracts.toString(this,
> > "description");
> > }
> >
> > @javax.inject.Inject
> > private ResultRepository resultRepo;
> > }
> > "
> >
> >
> >
> > ScenarioRepository.java
> > "
> > public class ScenarioRepository {
> > 
> > @Programmatic
> > public Scenario create(
> > final String description,
> > final int simulationYear,
> > final ModelCategory modelcat) {
> > final TitleBuffer buf = new TitleBuffer();
> >
> > Date dNow = new Date();
> > SimpleDateFormat ft =
> > new SimpleDateFormat ("dd---HH:mm");
> >
> > buf.append("SimYear-" + simulationYear + "_" + modelcat +
> > "_Created-");
> > buf.append(ft.format(dNow) + "_");
> > buf.append(description);
> >
> > final Scenario scenario =
> > container.newTransientInstance(Scenario.class);
> > scenario.setDescription(buf.toString());
> > scenario.setSimulationYear(simulationYear);
> > scenario.setModelCategory(modelcat);
> >
> > scenario.setBudget(
> > resultRepository.create(
> > buf.toString() + " - Analysis Results",
> > simulationYear,
> > AdjustStatus.valueOf("Created").ordinal()));
> >
> > container.persistIfNotAlready(scenario);
> > return scenario;
> > }
> >
> > @Inject
> > ResultRepository resultRepository;
> > }
> > "
> >
> >
> > Result.java
> > "
> > pu

Re: M:N association refuses to work

2017-04-06 Thread L Eder
Correcting this ...

ResultRepository.java
"
public class ResultRepository {

@Programmatic
public Result create(
final String description,
final int simulationYear,
final int status
) {
final Result result =
container.newTransientInstance(Result.class);

result.setDescription(description);
result.setSimulationYear(simulationYear);
result.setStatus(status);
return result;
}
}
"


2017-04-06 12:20 GMT-04:00, L Eder :
> Hi members of this forum:
>
> I have this situation - a Scenario entity comprised of many Result
> entities. And vice-versa.
>
> I then add the first result to a sortedset, using Scenario.runScenario().
>
> However when i add the second result object, in
> Scenario.adjustResult(), the first one is overwritten.
>
> Thanks for any help on this issue, Eder
>
> ---
>
> Scenario.java
> "
> public class Scenario implements Comparable {
>
> public String title() {
> return getDescription();
> }
>
> @Column(allowsNull = "false")
> @Property()
> @Getter @Setter
> private String description;
>
> @Column(allowsNull = "false")
> @Property()
> @Getter
> @Setter
> private int simulationYear;
>
> @Column(allowsNull = "false")
> @Property()
> @Getter @Setter
> private ModelCategory modelCategory;
>
> //@Property(hidden = Where.ANYWHERE)
> @Column(allowsNull = "true")
> @Property()
> @Getter @Setter
> private Result budget;
>
> @Persistent(table = "ScenarioResults")
> @Join(column = "scenario_id")
> //@Element(column = "res_id")
> @Element(column = "result_id")
> @Collection()
> @Getter @Setter
> @CollectionLayout(render = RenderType.EAGERLY)
> private SortedSet actuals = new TreeSet();
>
> 
> public Scenario importSeihan(
> @Parameter(fileAccept = ".xlsx")
> @ParameterLayout(named="Excel spreadsheet")
> final Blob spreadsheet){
> 
> getBudget().getCords().add(qitem);
> 
> }
>
> @Action()
> public Result runScenario(){
>
> getActuals().add(getBudget());
>
> return getBudget();
> }
>
> @Action()
> public Result adjustResult() {
> Date dNow = new Date();
> SimpleDateFormat ft =
> new SimpleDateFormat ("dd---HH:mm");
>
> /*final*/ Result adj = getBudget();
> String descr = getDescription() + "_adjust_" + ft.format(dNow)
> + "_[optional description]";
> adj.setDescription(descr);
> adj.setStatus(AdjustStatus.valueOf("InProgress").ordinal());
>
> getActuals().add(adj);
>
> return resultRepo.findByDescription(descr);
> }
>
>
> @Override
> public int compareTo(final Scenario other) {
> return org.apache.isis.applib.util.ObjectContracts.compare(this,
> other, "description");
> }
>
> @Override
> public String toString() {
> return org.apache.isis.applib.util.ObjectContracts.toString(this,
> "description");
> }
>
> @javax.inject.Inject
> private ResultRepository resultRepo;
> }
> "
>
>
>
> ScenarioRepository.java
> "
> public class ScenarioRepository {
> 
> @Programmatic
> public Scenario create(
> final String description,
> final int simulationYear,
> final ModelCategory modelcat) {
> final TitleBuffer buf = new TitleBuffer();
>
> Date dNow = new Date();
> SimpleDateFormat ft =
> new SimpleDateFormat ("dd---HH:mm");
>
> buf.append("SimYear-" + simulationYear + "_" + modelcat +
> "_Created-");
> buf.append(ft.format(dNow) + "_");
> buf.append(description);
>
> final Scenario scenario =
> container.newTransientInstance(Scenario.class);
> scenario.setDescription(buf.toString());
> scenario.setSimulationYear(simulationYear);
> scenario.setModelCategory(modelcat);
>
> scenario.setBudget(
> resultRepository.create(
> buf.toString() + " - Analysis Results",
> simulationYear,
> AdjustStatus.valueOf("Created").ordinal()));
>
> container.persistIfNotAlready(scenario);
> return scenario;
> }
>
> @Inject
> ResultRepository resultRepository;
> }
> "
>
>
> Result.java
> "
> public class Result implements Comparable {
>
> @Title
> @Column(allowsNull = "false")
> @Property(maxLength = 120)
> @Getter @Setter
> private String description;
>
> public String getDescription(){
>
> return description;
> }
>
> @Column(allowsNull = "false")
> @Property()
> @Getter @Setter
> private int simulationYear;
>
> @Column(allowsNull = "false")
> @Property()
> @Getter @Setter
> private int status;
>
> @CollectionLayout(render = RenderType