Hi,
I've been using Apache Isis for quite some time now, and I'm hugely
impressed with some of the work in this framework.
I have a problem in designing my Repository interfaces, and I'd
like some advice on how I ought to be addressing it. The problem in
general is that my repositories for the default object store, implement
interfaces that are similar to the CrudRepository interface in
Spring-JPA (1). The CrudRepository has a method of signature "T save(T
entity)", which is responsible for creating new persistent instances. My
repositories implement a similar method, like the following:
@Named("Chart of Accounts")
public class AccountRepositoryDefault extends
AbstractFactoryAndRepository implements AccountRepository
{
// {{ Create new (already persisted) Account
@Override
public Account newAccount(Account newAccount)
{
Account account = newTransientInstance(Account.class);
copyProperties(newAccount, account); // Hack. Copy properties
from the argument to the transient instance.
persist(account);
return account;
}
// }}
// {{ all Accounts
@Override
@Exploration
public List<Account> allAccounts()
{
return allInstances(Account.class);
}
// }}
// {{ unique Account
public Account findAccountById(final String accountId)
{
return uniqueMatch(Account.class, new Filter<Account>()
{
@Override
public boolean accept(Account pojo)
{
return pojo.getAccountId().equals(accountId);
}
});
}
// }}
... other methods
}
When I attempt to perform this action (of saving/creating a new entity)
exposed by the repository, both in the default Swing viewer as well as
the HTML viewer, I'm presented with a dialog requesting an input of an
already created instance of <T>, i.e. Account in this case. While this
behavior of the Isis viewers is understandable, this is quite contrary
to my expectation that I would be presented with a dialog listing all
the enabled properties of an Account that would allow for creation of a
new instance on the fly.
To explain my predicament further, I am attempting to use the domain
model constructed with Isis, in a Java EE 6 app where the domain objects
would be created in facelets and managed beans in the presentation tier,
eventually used by the application and domain layers, finally persisting
the objects to JPA repositories. I could change the repository interface
to one that accepts all attributes of a domain object, but it would be a
design smell to provide all these arguments to the repository, from an
already constructed domain object.
I'd like to know, how I could go about achieving this requirement in
Isis; perhaps a new annotation like @Expand needs to be introduced? I
can understand that this is possibly a feature request, and if this is
the case, I'm quite open to submitting a patch. I'd appreciate any
inputs in this area.
Thanks,
Vineet
Links:
1.
https://github.com/SpringSource/spring-data-commons/blob/master/spring-data-commons-core/src/main/java/org/springframework/data/repository/CrudRepository.java