Thanks Dan however still not succeed. Is something missing below?
Also, how do i link the ComponentLineItem collection to Component so
as to persist it?
ComponentLineItem.java
"
@ViewModel
public class ComponentLineItem {
@Column(allowsNull = "true")
@Getter @Setter
private String description;
// //////////////////////////////////////
@Column(allowsNull = "true")
@Getter @Setter
private String partNumber;
// //////////////////////////////////////
@Column(allowsNull = "true")
@Getter @Setter
private ComponentOrigin origin;
// //////////////////////////////////////
// Q: Do i need the method apply() here?
}
"
Componentmenu.java
"
public List<ComponentLineItem> importExcel(
@Parameter(fileAccept = ".xlsx")
@ParameterLayout(named="Excel spreadsheet")
final org.apache.isis.applib.value.Blob spreadsheet) {
final List<ComponentLineItem> lineItems =
excelService.fromExcel(spreadsheet,
ComponentLineItem.class, "Sheet1");
container.informUser(lineItems.size() + " items imported");
for (final ComponentLineItem lineItem : lineItems) {
container.persistIfNotAlready(lineItem);
}
return lineItems;
}
"
2017-03-09 7:35 GMT-04:00, Dan Haywood <[email protected]>:
> Rather than importing directly into the entity (Component) you'll should
> import to view models; these can then do the look up from the identifier of
> the entity to the entity itself.
>
> See Estatio for some examples, eg
> https://github.com/estatio/estatio/tree/master/estatioapp/impmgr/src/main/java/org/estatio/app/services/indexmaint
>
> HTH
> Dan
>
>
>
> On Thu, 9 Mar 2017 at 12:24 L Eder <[email protected]> wrote:
>
>> The excel sheet content:
>> "
>> Category Origin firstdate LastDate PartNumber
>> Description
>> Mat Imp 1/1/2017 2/28/2018
>> A-2103-753-A BM1(2016-QF)
>> "
>>
>> The incorrect result, in columns Category and Origin, displayed after a
>> import:
>> Description Part Number First Date Last Date Category
>> Origin
>> BM1(2016-QF) A-2103-753-A 01-01-2017 28-02-2018 (none)
>> (none)
>>
>>
>> The source code:
>>
>> ComponentRepository.java
>> "
>> @DomainService(
>> nature = NatureOfService.DOMAIN,
>> repositoryFor = Component.class
>> )
>> public class ComponentRepository {
>>
>> public static final WorksheetSpec WORKSHEET_SPEC =
>> new WorksheetSpec(Component.class, "Sheet1");
>>
>> @Programmatic
>> public java.util.List<Component> listAll() {
>> return container.allInstances(Component.class);
>> }
>>
>> @Programmatic
>> public Component findByDescription(
>> final String description
>> ) {
>> return container.uniqueMatch(
>> new org.apache.isis.applib.query.QueryDefault<>(
>> Component.class,
>> "findByDescription",
>> "description", description));
>> }
>>
>> @Programmatic
>> public java.util.List<Component> findByDescriptionContains(
>> final String description
>> ) {
>> return container.allMatches(
>> new org.apache.isis.applib.query.QueryDefault<>(
>> Component.class,
>> "findByDescriptionContains",
>> "description", description));
>> }
>>
>> @Programmatic
>> public Component create(
>> final String description,
>> final String partNumber,
>> final LocalDate firstDate,
>> final LocalDate lastDate,
>> final ComponentCategory category,
>> final ComponentOrigin origin) {
>> final Component component =
>> container.newTransientInstance(Component.class);
>> component.setDescription(description);
>> component.setPartNumber(partNumber);
>> component.setFirstDate(firstDate);
>> component.setLastDate(lastDate);
>> component.setCategory(category);
>> component.setOrigin(origin);
>> container.persistIfNotAlready(component);
>> return component;
>> }
>>
>> @Programmatic
>> public Component findOrCreate(
>> final String description
>> ) {
>> Component component = findByDescription(description);
>> if (component == null) {
>> // (commented until i solve the error here) component =
>> create(description);
>> }
>> return component;
>> }
>>
>> @Programmatic
>> public List<Component> importExcel(
>> final Blob spreadsheet) {
>> final List<Component> components =
>> excelService.fromExcel(spreadsheet, WORKSHEET_SPEC);
>> container.informUser(components.size() + " items imported");
>>
>> for (final Component obj : components) {
>> container.persistIfNotAlready(obj);
>> }
>>
>> return components;
>> }
>>
>> @javax.inject.Inject
>> org.apache.isis.applib.DomainObjectContainer container;
>>
>> @javax.inject.Inject
>> private ExcelService excelService;
>> }
>> "
>>
>> ComponentMenu.java
>> "
>> @DomainService(
>> nature = NatureOfService.VIEW_MENU_ONLY
>> )
>> @DomainServiceLayout(
>> named = "Components",
>> menuOrder = "210"
>> )
>> public class ComponentMenu {
>>
>> @Action(
>> semantics = SemanticsOf.SAFE,
>> restrictTo = RestrictTo.PROTOTYPING
>> )
>> @ActionLayout(
>> bookmarking = BookmarkPolicy.AS_ROOT
>> )
>> @MemberOrder(sequence = "1")
>> public java.util.List<Component> allComponents() {
>> return componentrepository.listAll();
>> }
>>
>> @Action(
>> semantics = SemanticsOf.SAFE
>> )
>> @ActionLayout(
>> bookmarking = BookmarkPolicy.AS_ROOT
>> )
>> @MemberOrder(sequence = "2")
>> public java.util.List<Component> findByDescription(
>> @ParameterLayout(named="Description")
>> final String description
>> ) {
>> return
>> componentrepository.findByDescriptionContains(description);
>> }
>>
>> @Action(
>> )
>> @MemberOrder(sequence = "3")
>> public Component create(
>> @ParameterLayout(named="Description") final String
>> description,
>> @ParameterLayout(named="Part Number") final String
>> partNumber,
>> @ParameterLayout(named="First Date") final LocalDate
>> firstDate,
>> @ParameterLayout(named="Last Date") final LocalDate lastDate,
>> @ParameterLayout(named="Category") final ComponentCategory
>> category,
>> @ParameterLayout(named="Origin") final ComponentOrigin origin
>> ) {
>> return componentrepository.create(
>> description,
>> partNumber,
>> firstDate,
>> lastDate,
>> category,
>> origin);
>> }
>>
>> @Action(
>> )
>> @MemberOrder(sequence = "4")
>> public List<Component> importExcel(
>> @Parameter(fileAccept = ".xlsx")
>> @ParameterLayout(named="Excel spreadsheet")
>> final org.apache.isis.applib.value.Blob spreadsheet) {
>> return componentrepository.importExcel(spreadsheet);
>> }
>>
>> @javax.inject.Inject
>> ComponentRepository componentrepository;
>>
>> @javax.inject.Inject
>> private ModelRepository modelRepo;
>> }
>> "
>>
>> Component.java
>> "
>> @PersistenceCapable(
>> identityType = IdentityType.DATASTORE,
>> schema = "PPB",
>> table = "Component"
>> )
>> @DatastoreIdentity(
>> strategy = IdGeneratorStrategy.IDENTITY,
>> column = "id")
>> @Version(
>> strategy = VersionStrategy.VERSION_NUMBER,
>> column = "version")
>> @Queries({
>> @Query(
>> name = "find", language = "JDOQL",
>> value = "SELECT "
>> + "FROM domainapp.dom.PPB.Component "),
>> @Query(
>> name = "findByDescriptionContains", language = "JDOQL",
>> value = "SELECT "
>> + "FROM domainapp.dom.PPB.Component "
>> + "WHERE description.indexOf(:description) >= 0
>> "),
>> @Query(
>> name = "findByDescription", language = "JDOQL",
>> value = "SELECT "
>> + "FROM domainapp.dom.PPB.Component "
>> + "WHERE description == :description ")
>> })
>> @DomainObject(
>> editing = Editing.DISABLED,
>> bounded=true
>> )
>> @DomainObjectLayout(
>> bookmarking = BookmarkPolicy.AS_ROOT
>> )
>> @MemberGroupLayout(columnSpans = {6,6,0,12}, left={"General"},
>> middle="Details")
>>
>> public class Component implements Comparable<Component> {
>>
>> @Title(sequence="1")
>> @MemberOrder(name="General", sequence="1")
>> @Column(allowsNull = "false")
>> @Getter @Setter
>> private String description;
>>
>> // region > part number (property)
>>
>> @MemberOrder(name="General", sequence="2")
>> @Column(allowsNull = "true")
>> @Getter @Setter
>> private String partNumber;
>> // endregion
>>
>> // region > first date, last date (property)
>>
>> @MemberOrder(name="General", sequence="3")
>> @Column(allowsNull = "false")
>> @Getter @Setter
>> private LocalDate firstDate;
>>
>> @MemberOrder(name="General", sequence="4")
>> @Column(allowsNull = "false")
>> @Getter @Setter
>> private LocalDate lastDate;
>> //endregion
>>
>> // region > category (property)
>>
>> @Column(allowsNull = "true")
>> @MemberOrder(name="Details", sequence="1")
>> @Getter @Setter
>> private ComponentCategory category;
>>
>> @Column(allowsNull = "true")
>> @MemberOrder(name="Details", sequence="2")
>> @Getter @Setter
>> private ComponentOrigin origin;
>> // endregion
>>
>> // region > associated models (property)
>> // endregion
>>
>> //region > compareTo, toString
>> @Override
>> public int compareTo(final Component 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");
>> }
>> //endregion
>>
>> }
>> "
>>
>>
>>
>> 2017-03-09 1:00 GMT-04:00, Stephen Cameron <[email protected]>:
>> > Code snippet?
>> >
>> > On Thu, Mar 9, 2017 at 2:04 PM, L Eder <[email protected]> wrote:
>> >
>> >> Hi members:
>> >>
>> >> In this issue only the value property columns are imported.
>> >> Except the reference property columns, who values appear wrongly as
>> >> '(none)'.
>> >>
>> >> Has anyone experienced this issue?
>> >> Thanks, eder
>> >>
>> >
>>
>