| package domainapp.modules.simple.dom.so; |
| |
| import java.util.Comparator; |
| |
| import javax.inject.Inject; |
| import javax.jdo.annotations.IdGeneratorStrategy; |
| import javax.jdo.annotations.IdentityType; |
| import javax.jdo.annotations.VersionStrategy; |
| import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
| |
| import org.apache.isis.applib.annotation.Action; |
| import org.apache.isis.applib.annotation.ActionLayout; |
| import org.apache.isis.applib.annotation.DomainObject; |
| import org.apache.isis.applib.annotation.DomainObjectLayout; |
| import org.apache.isis.applib.annotation.MemberOrder; |
| import org.apache.isis.applib.annotation.PromptStyle; |
| import org.apache.isis.applib.jaxb.PersistentEntityAdapter; |
| import org.apache.isis.applib.services.message.MessageService; |
| import org.apache.isis.applib.services.repository.RepositoryService; |
| import org.apache.isis.applib.services.title.TitleService; |
| |
| import static org.apache.isis.applib.annotation.SemanticsOf.IDEMPOTENT; |
| import static org.apache.isis.applib.annotation.SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE; |
| |
| import lombok.Getter; |
| import lombok.Setter; |
| import lombok.ToString; |
| import lombok.val; |
| |
| import domainapp.modules.simple.types.Name; |
| import domainapp.modules.simple.types.Notes; |
| |
| @javax.jdo.annotations.PersistenceCapable(identityType=IdentityType.DATASTORE, schema = "SIMPLE") |
| @javax.jdo.annotations.DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, column="id") |
| @javax.jdo.annotations.Queries({ |
| @javax.jdo.annotations.Query( |
| name = "findByName", |
| value = "SELECT " + |
| "FROM domainapp.modules.simple.dom.so.SimpleObject " + |
| "WHERE name.indexOf(:name) >= 0" |
| ), |
| @javax.jdo.annotations.Query( |
| name = "findByNameExact", |
| value = "SELECT " + |
| "FROM domainapp.modules.simple.dom.so.SimpleObject " + |
| "WHERE name == :name" |
| ) |
| }) |
| @javax.jdo.annotations.Version(strategy= VersionStrategy.DATE_TIME, column="version") |
| @javax.jdo.annotations.Unique(name="SimpleObject_name_UNQ", members = {"name"}) |
| @DomainObject(objectType = "simple.SimpleObject") |
| @DomainObjectLayout() |
| @XmlJavaTypeAdapter(PersistentEntityAdapter.class) |
| @ToString(onlyExplicitlyIncluded = true) |
| public class SimpleObject implements Comparable<SimpleObject> { |
| |
| public static SimpleObject withName(String name) { |
| val simpleObject = new SimpleObject(); |
| simpleObject.setName(name); |
| return simpleObject; |
| } |
| |
| @Inject RepositoryService repositoryService; |
| @Inject TitleService titleService; |
| @Inject MessageService messageService; |
| |
| private SimpleObject() { |
| } |
| |
| public String title() { |
| return "Object: " + getName(); |
| } |
| |
| |
| @Name |
| @Getter @Setter @ToString.Include |
| @MemberOrder(name = "Name", sequence = "1") |
| private String name; |
| |
| @Notes |
| @Getter @Setter |
| @MemberOrder(name = "Name", sequence = "2") |
| private String notes; |
| |
| |
| @Action(semantics = IDEMPOTENT, associateWith = "name") |
| @ActionLayout(promptStyle = PromptStyle.INLINE) |
| public SimpleObject updateName( |
| @Name final String name) { |
| setName(name); |
| return this; |
| } |
| public String default0UpdateName() { |
| return getName(); |
| } |
| public String validate0UpdateName(String newName) { |
| for (char prohibitedCharacter : "&%$!".toCharArray()) { |
| if( newName.contains(""+prohibitedCharacter)) { |
| return "Character '" + prohibitedCharacter + "' is not allowed."; |
| } |
| } |
| return null; |
| } |
| |
| |
| @Action(semantics = NON_IDEMPOTENT_ARE_YOU_SURE, associateWith = "name") |
| @ActionLayout( |
| position = ActionLayout.Position.PANEL, |
| describedAs = "Deletes this object from the persistent datastore" |
| ) |
| public void delete() { |
| final String title = titleService.titleOf(this); |
| messageService.informUser(String.format("'%s' deleted", title)); |
| repositoryService.removeAndFlush(this); |
| } |
| |
| |
| |
| private final static Comparator<SimpleObject> comparator = |
| Comparator.comparing(SimpleObject::getName); |
| |
| @Override |
| public int compareTo(final SimpleObject other) { |
| return comparator.compare(this, other); |
| } |
| |
| } |