Skip to content

Commit

Permalink
#181 ProcessInstance.PARAM_ViewSelectedIds
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Feb 24, 2017
1 parent 6b755d0 commit d0def0e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public final class ProcessInstance
private static final transient Logger logger = LogManager.getLogger(ProcessInstance.class);

public static final String PARAM_ViewId = "$WEBUI_ViewId";
public static final String PARAM_ViewSelectedIds = "$WEBUI_ViewSelectedIds";

@Autowired
@Lazy
Expand Down Expand Up @@ -408,16 +409,15 @@ private static final JSONReferencing extractJSONReferencing(final ProcessInfo pr
.setLimit(maxRecordAllowedToSelect + 1)
.create()
.listIds();
if(recordIds.isEmpty())
if (recordIds.isEmpty())
{
return null;
}
else if (recordIds.size() > maxRecordAllowedToSelect)
{
throw new AdempiereException("Selecting more than " + maxRecordAllowedToSelect + " records is not allowed");
}



final TableRecordReference firstRecordRef = TableRecordReference.of(tableName, recordIds.get(0));
final int adWindowId = RecordZoomWindowFinder.findAD_Window_ID(firstRecordRef); // assume all records are from same window
return JSONReferencing.of(adWindowId, recordIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory;
import de.metas.ui.web.window.model.Document;
import de.metas.ui.web.window.model.Document.CopyMode;
import de.metas.ui.web.window.model.DocumentCollection;

/*
* #%L
Expand Down Expand Up @@ -70,11 +69,8 @@ public class ProcessInstancesRepository
@Autowired
private DocumentDescriptorFactory documentDescriptorFactory;
@Autowired
private DocumentCollection documentsCollection;
@Autowired
private IDocumentViewsRepository documentViewsRepo;


private final LoadingCache<DocumentId, ProcessInstance> processInstances = CacheBuilder.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES)
.removalListener(new RemovalListener<DocumentId, ProcessInstance>()
Expand Down Expand Up @@ -125,7 +121,7 @@ public ProcessInstance createNewProcessInstance(final int adProcessId, final JSO
processInstances.put(adPInstanceId, pinstance.copy(CopyMode.CheckInReadonly));
return pinstance;
}

private ProcessInfo createProcessInfo(final int adProcessId, final JSONCreateProcessInstanceRequest request)
{
// Validate request's AD_Process_ID
Expand All @@ -140,33 +136,37 @@ private ProcessInfo createProcessInfo(final int adProcessId, final JSONCreatePro
final String tableName;
final int recordId;
final String sqlWhereClause;

//
// View
final String viewId = Strings.emptyToNull(request.getViewId());
final String viewSelectedIdsAsStr;
final DocumentPath singleDocumentPath = request.getSingleDocumentPath();
if (!Check.isEmpty(viewId))
{
final IDocumentViewSelection view = documentViewsRepo.getView(viewId);
final Set<DocumentId> viewDocumentIds = request.getViewDocumentIds();
viewSelectedIdsAsStr = DocumentId.toCommaSeparatedString(viewDocumentIds);
final int view_AD_Window_ID = view.getAD_Window_ID();
tableName = documentDescriptorFactory.getTableNameOrNull(view_AD_Window_ID);

if (viewDocumentIds.size() == 1)
{
recordId = viewDocumentIds.iterator().next().toInt();
final DocumentId singleDocumentId = viewDocumentIds.iterator().next();
recordId = singleDocumentId.toIntOr(-1);
}
else
{
recordId = -1;
}

sqlWhereClause = view.getSqlWhereClause(viewDocumentIds);
}
//
// Single document call
else if (singleDocumentPath != null)
{
viewSelectedIdsAsStr = null;
tableName = documentDescriptorFactory.getTableNameOrNull(singleDocumentPath.getAD_Window_ID(), singleDocumentPath.getDetailId());
recordId = singleDocumentPath.getSingleRowId().toInt();
sqlWhereClause = null;
Expand All @@ -175,6 +175,7 @@ else if (singleDocumentPath != null)
// From menu
else
{
viewSelectedIdsAsStr = null;
tableName = null;
recordId = -1;
sqlWhereClause = null;
Expand All @@ -189,11 +190,11 @@ else if (singleDocumentPath != null)
//
.setLoadParametersFromDB(true) // important: we need to load the existing parameters from database, besides the internal ones we are adding here
.addParameter(ProcessInstance.PARAM_ViewId, viewId) // internal parameter
.addParameter(ProcessInstance.PARAM_ViewSelectedIds, viewSelectedIdsAsStr) // internal parameter
//
.build();
}


private ProcessInstance retrieveProcessInstance(final DocumentId adPInstanceId)
{
Check.assumeNotNull(adPInstanceId, "Parameter adPInstanceId is not null");
Expand Down Expand Up @@ -229,7 +230,7 @@ private ProcessInstance retrieveProcessInstance(final DocumentId adPInstanceId)
public <R> R forProcessInstanceReadonly(final int pinstanceIdAsInt, final Function<ProcessInstance, R> processor)
{
final DocumentId pinstanceId = DocumentId.of(pinstanceIdAsInt);

try
{
try (final IAutoCloseable readLock = processInstances.get(pinstanceId).lockForReading())
Expand All @@ -247,19 +248,19 @@ public <R> R forProcessInstanceReadonly(final int pinstanceIdAsInt, final Functi
public <R> R forProcessInstanceWritable(final int pinstanceIdAsInt, final Function<ProcessInstance, R> processor)
{
final DocumentId pinstanceId = DocumentId.of(pinstanceIdAsInt);

try
{
try (final IAutoCloseable writeLock = processInstances.get(pinstanceId).lockForWriting())
{
final ProcessInstance processInstance = processInstances.get(pinstanceId).copy(CopyMode.CheckOutWritable);

final R result = processor.apply(processInstance);

// Actually put it back
processInstance.saveIfValidAndHasChanges(false); // throwEx=false
processInstances.put(pinstanceId, processInstance.copy(CopyMode.CheckInReadonly));

return result;
}
}
Expand Down

0 comments on commit d0def0e

Please sign in to comment.