Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
fixes #14 #15 #16 #17
Browse files Browse the repository at this point in the history
  • Loading branch information
danhaywood committed Mar 1, 2017
1 parent 96f6370 commit 733b5c9
Show file tree
Hide file tree
Showing 18 changed files with 752 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.isis.applib.AppManifest;
import org.apache.isis.applib.fixturescripts.FixtureScript;

import org.isisaddons.module.command.CommandModule;
import org.isisaddons.module.fakedata.FakeDataModule;
import org.isisaddons.module.freemarker.dom.FreeMarkerModule;
import org.isisaddons.module.stringinterpolator.StringInterpolatorModule;
Expand All @@ -52,6 +53,7 @@ public DocumentModuleAppManifest() {
DocumentFixtureModule.class,
DocumentAppModule.class,

CommandModule.class,
FakeDataModule.class,

FreemarkerDocRenderingModule.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.incode.module.document.app.services.fakesched;

import java.util.List;

import javax.inject.Inject;

import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.DomainServiceLayout;
import org.apache.isis.applib.annotation.NatureOfService;
import org.apache.isis.applib.annotation.ParameterLayout;
import org.apache.isis.applib.annotation.SemanticsOf;
import org.apache.isis.applib.services.xactn.TransactionService;
import org.apache.isis.core.runtime.authentication.standard.SimpleSession;

import org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo;
import org.isisaddons.module.command.dom.BackgroundCommandServiceJdoRepository;
import org.isisaddons.module.command.dom.CommandJdo;

@DomainService(
nature = NatureOfService.VIEW_MENU_ONLY,
objectType = "incodeCommunicationsDemo.FakeScheduler"
)
@DomainServiceLayout(
named = "Fakes",
menuBar = DomainServiceLayout.MenuBar.SECONDARY,
menuOrder = "110"
)
public class FakeScheduler {

@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
public void runBackgroundCommands(
@ParameterLayout(named = "Wait for (ms)")
final Integer waitFor) throws InterruptedException {

List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
if(commands.isEmpty()) {
throw new IllegalStateException("There are no commands not yet started");
}

transactionService.nextTransaction();

BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec =
new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });

final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
thread.start();

thread.join(waitFor);

commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
if(!commands.isEmpty()) {
throw new IllegalStateException("There are still " + commands.size() + " not yet started");
}
}

// using a validateXxx rather than a hideXxx because of https://issues.apache.org/jira/browse/ISIS-1593
public String validateRunBackgroundCommands(final Integer waitFor) {
List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
return commands.isEmpty() ? "No background commands to run" : null;
}

public Integer default0RunBackgroundCommands() {
return 5000;
}

@Inject
protected BackgroundCommandServiceJdoRepository backgroundCommandRepository;

@Inject
protected TransactionService transactionService;

}
11 changes: 11 additions & 0 deletions dom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Copyright 2014~2015 Dan Haywood
</developers>

<properties>
<isis-module-command.version>1.14.0</isis-module-command.version>
<isis-module-fakedata.version>1.14.0</isis-module-fakedata.version>
<incode-module-base.version>1.14.0</incode-module-base.version>
<incode-module-unittestsupport.version>1.14.0</incode-module-unittestsupport.version>
Expand Down Expand Up @@ -236,6 +237,11 @@ Copyright 2014~2015 Dan Haywood
<version>${incode-module-unittestsupport.version}</version>
</dependency>

<dependency>
<groupId>org.isisaddons.module.command</groupId>
<artifactId>isis-module-command-dom</artifactId>
<version>${isis-module-command.version}</version>
</dependency>
<dependency>
<groupId>org.isisaddons.module.fakedata</groupId>
<artifactId>isis-module-fakedata-dom</artifactId>
Expand Down Expand Up @@ -279,6 +285,11 @@ Copyright 2014~2015 Dan Haywood
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.isisaddons.module.command</groupId>
<artifactId>isis-module-command-dom</artifactId>
</dependency>

<dependency>
<groupId>org.isisaddons.module.fakedata</groupId>
<artifactId>isis-module-fakedata-dom</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2016 Dan Haywood
*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.incode.module.document.dom.impl.applicability;

import java.util.Collections;
import java.util.List;

import org.incode.module.document.dom.impl.docs.DocumentTemplate;

/**
* To allow documents to be rendered that are by default attached to no other objects.
*/
public class AttachmentAdvisorAttachToNone extends AttachmentAdvisorAbstract<Object> {

public AttachmentAdvisorAttachToNone() {
super(Object.class);
}

@Override
protected List<PaperclipSpec> doAdvise(
final DocumentTemplate documentTemplate,
final Object domainObject) {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<bs3:row>
<bs3:col span="12">
<cpt:fieldSet name="Identifier">
<cpt:action id="delete"/>
<cpt:property id="name"/>
</cpt:fieldSet>
</bs3:col>
Expand Down Expand Up @@ -59,7 +60,7 @@
<cpt:fieldSet name="Details">
<cpt:property id="type"/>
<cpt:property id="state"/>
<cpt:property id="mimeType"/>
<cpt:property id="mimeType" hidden="ALL_TABLES"/>
</cpt:fieldSet>
</bs3:col>
</bs3:row>
Expand All @@ -68,13 +69,18 @@
<bs3:row>
<bs3:col span="12">
<cpt:fieldSet name="Dates">
<cpt:property id="createdAt"/>
<cpt:property id="renderedAt"/>
<cpt:property id="createdAt" hidden="ALL_TABLES"/>
<cpt:property id="renderedAt" hidden="ALL_TABLES"/>
</cpt:fieldSet>
</bs3:col>
</bs3:row>
</bs3:tab>
</bs3:tabGroup>
<cpt:fieldSet name="Related">
<cpt:property id="supports" hidden="ALL_TABLES"/>
<!-- if communication module also configured, then it will contribute a 'coverNoteFor' property -->
<cpt:property id="coverNoteFor" hidden="ALL_TABLES"/>
</cpt:fieldSet>
</bs3:col>
<bs3:col span="6">
<bs3:tabGroup>
Expand All @@ -83,7 +89,7 @@
<bs3:col span="12">
<cpt:fieldSet name="Content" id="content">
<cpt:action id="movedToExternalUrl"/>
<cpt:property id="sort"/>
<cpt:property id="sort" hidden="ALL_TABLES"/>
<cpt:property id="blob" hidden="ALL_TABLES">
</cpt:property>
<cpt:property id="clob" hidden="ALL_TABLES">
Expand Down Expand Up @@ -117,26 +123,33 @@
<bs3:tab name="Attachments">
<bs3:row>
<bs3:col span="12">
<cpt:collection id="supportingDocuments">
<cpt:action id="attachSupportingPdf"/>
</cpt:collection>
<cpt:collection id="attachedTo">
<cpt:describedAs>Objects that this document attaches to</cpt:describedAs>
</cpt:collection>
<cpt:collection id="documentsAttachingToThisDocument"/>
</bs3:col>
</bs3:row>
</bs3:tab>
<bs3:tab name="Background commands">
<bs3:tab name="Communications">
<bs3:row>
<bs3:col span="12">
<cpt:collection id="backgroundCommands" defaultView="table"/>
<cpt:collection id="communicationAttachments" defaultView="table">
<cpt:named>New communication will have these attachments (emails also have a cover note)</cpt:named>
<cpt:action id="sendByEmail"/>
<cpt:action id="sendByPost"/>
</cpt:collection>
<cpt:collection id="communications" defaultView="table">
<cpt:named>Communications (already sent)</cpt:named>
</cpt:collection>
</bs3:col>
</bs3:row>
</bs3:tab>
<bs3:tab name="dummyTabToForceFirstTabToAppear2">
<bs3:tab name="Background commands">
<bs3:row>
<bs3:col span="12">
<cpt:fieldSet name="dummy2">
<cpt:property id="dummy2"/>
</cpt:fieldSet>
<cpt:collection id="backgroundCommands" defaultView="table"/>
</bs3:col>
</bs3:row>
</bs3:tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@

import javax.inject.Inject;

import com.google.common.collect.Lists;

import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.ActionLayout;
import org.apache.isis.applib.annotation.CollectionLayout;
import org.apache.isis.applib.annotation.Contributed;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.Mixin;
import org.apache.isis.applib.annotation.NatureOfService;
import org.apache.isis.applib.annotation.Programmatic;
import org.apache.isis.applib.annotation.SemanticsOf;
import org.apache.isis.applib.services.queryresultscache.QueryResultsCache;
import org.apache.isis.applib.services.tablecol.TableColumnOrderService;

import org.incode.module.document.dom.DocumentModule;
import org.incode.module.document.dom.impl.paperclips.Paperclip;
Expand Down Expand Up @@ -68,14 +73,65 @@ public static class ActionDomainEvent extends DocumentModule.ActionDomainEvent<D
}

public boolean hide$$() {
return document instanceof DocumentTemplate && $$().isEmpty();
if (document instanceof DocumentTemplate && $$().isEmpty()) {
return true;
}
if(document instanceof Document) {
// hide for supporting documents
final Document doc = (Document) document;
final Document supportedBy = supportsEvaluator.supportedBy(doc);
return supportedBy != null;
}
return false;
}

//region > injected services

@Inject
Document_supports.Evaluator supportsEvaluator;

@Inject
PaperclipRepository paperclipRepository;
@Inject
QueryResultsCache queryResultsCache;
//endregion


@DomainService(
nature = NatureOfService.DOMAIN,
menuOrder = "100"
)
public static class ColumnOrderService implements TableColumnOrderService {

@Override
public List<String> orderParented(
final Object domainObject,
final String collectionId,
final Class<?> collectionType,
final List<String> propertyIds) {
if (!Paperclip.class.isAssignableFrom(collectionType)) {
return null;
}

if (!(domainObject instanceof DocumentAbstract)) {
return null;
}

if (!"attachedTo".equals(collectionId)) {
return null;
}

final List<String> trimmedPropertyIds = Lists.newArrayList(propertyIds);
trimmedPropertyIds.remove("document");
trimmedPropertyIds.remove("documentDate");
trimmedPropertyIds.remove("documentState");
return trimmedPropertyIds;
}

@Override
public List<String> orderStandalone(final Class<?> collectionType, final List<String> propertyIds) {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.incode.module.document.dom.impl.applicability.Applicability;
import org.incode.module.document.dom.impl.applicability.ApplicabilityRepository;
import org.incode.module.document.dom.impl.applicability.AttachmentAdvisor;
import org.incode.module.document.dom.impl.applicability.AttachmentAdvisorAttachToNone;
import org.incode.module.document.dom.impl.applicability.RendererModelFactory;
import org.incode.module.document.dom.impl.renderers.Renderer;
import org.incode.module.document.dom.impl.renderers.RendererFromBytesToBytes;
Expand Down Expand Up @@ -531,7 +532,13 @@ public Applicability applicable(
final Class<?> domainClass,
final Class<? extends RendererModelFactory> renderModelFactoryClass,
final Class<? extends AttachmentAdvisor> attachmentAdvisorClass) {
return applicable(domainClass.getName(), renderModelFactoryClass, attachmentAdvisorClass);
return applicable(
domainClass.getName(),
renderModelFactoryClass,
attachmentAdvisorClass != null
? attachmentAdvisorClass
: AttachmentAdvisorAttachToNone.class
);
}

@Programmatic
Expand Down
Loading

0 comments on commit 733b5c9

Please sign in to comment.