Skip to content
Snippets Groups Projects
Commit a1a7e9c4 authored by jakubs's avatar jakubs
Browse files

BIS-21 SP-106: add entity operations in progress to application service

SVN: 25606
parent 77c8b43f
No related branches found
No related tags found
No related merge requests found
...@@ -72,6 +72,7 @@ import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService; ...@@ -72,6 +72,7 @@ import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService;
import ch.systemsx.cisd.openbis.generic.shared.IServer; import ch.systemsx.cisd.openbis.generic.shared.IServer;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchableEntityKind; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchableEntityKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.EntityOperationsState;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus;
...@@ -1322,52 +1323,78 @@ public class ETLService extends AbstractCommonServer<IETLLIMSService> implements ...@@ -1322,52 +1323,78 @@ public class ETLService extends AbstractCommonServer<IETLLIMSService> implements
AtomicEntityOperationDetails operationDetails, IProgressListener progressListener) AtomicEntityOperationDetails operationDetails, IProgressListener progressListener)
{ {
final Session session = getSession(sessionToken); TechId registrationId = operationDetails.getRegistrationIdOrNull();
List<Space> spacesCreated = createSpaces(session, operationDetails, progressListener); EntityOperationsInProgress.getInstance().addRegistrationPending(registrationId);
List<Material> materialsCreated = try
createMaterials(session, operationDetails, progressListener); {
List<Project> projectsCreated = createProjects(session, operationDetails, progressListener); final Session session = getSession(sessionToken);
List<Experiment> experimentsCreated = List<Space> spacesCreated = createSpaces(session, operationDetails, progressListener);
createExperiments(session, operationDetails, progressListener);
List<Sample> samplesCreated = createSamples(session, operationDetails, progressListener); List<Material> materialsCreated =
createMaterials(session, operationDetails, progressListener);
List<Sample> samplesUpdated = updateSamples(session, operationDetails, progressListener); List<Project> projectsCreated =
createProjects(session, operationDetails, progressListener);
List<ExternalData> dataSetsCreated = List<Experiment> experimentsCreated =
createDataSets(session, operationDetails, progressListener); createExperiments(session, operationDetails, progressListener);
List<ExternalData> dataSetsUpdated = List<Sample> samplesCreated =
updateDataSets(session, operationDetails, progressListener); createSamples(session, operationDetails, progressListener);
// If the id is not null, the caller wants to persist the fact that the operation was List<Sample> samplesUpdated =
// invoked and completed; updateSamples(session, operationDetails, progressListener);
// if the id is null, the caller does not care.
TechId registrationId = operationDetails.getRegistrationIdOrNull(); List<ExternalData> dataSetsCreated =
if (null != registrationId) createDataSets(session, operationDetails, progressListener);
List<ExternalData> dataSetsUpdated =
updateDataSets(session, operationDetails, progressListener);
// If the id is not null, the caller wants to persist the fact that the operation was
// invoked and completed;
// if the id is null, the caller does not care.
if (null != registrationId)
{
daoFactory.getEntityOperationsLogDAO().addLogEntry(registrationId.getId());
}
return new AtomicEntityOperationResult(spacesCreated, projectsCreated,
experimentsCreated, samplesUpdated, samplesCreated, materialsCreated,
dataSetsCreated, dataSetsUpdated);
} finally
{ {
daoFactory.getEntityOperationsLogDAO().addLogEntry(registrationId.getId()); EntityOperationsInProgress.getInstance().removeRegistrationPending(registrationId);
} }
return new AtomicEntityOperationResult(spacesCreated, projectsCreated, experimentsCreated,
samplesUpdated, samplesCreated, materialsCreated, dataSetsCreated, dataSetsUpdated);
} }
@Override @Override
public Boolean didEntityOperationsSucceed(String token, TechId registrationId) public EntityOperationsState didEntityOperationsSucceed(String token, TechId registrationId)
{ {
if (registrationId == null) if (registrationId == null)
{ {
return false; return EntityOperationsState.NO_OPERATION;
}
if (EntityOperationsInProgress.getInstance().isRegistrationPending(registrationId))
{
return EntityOperationsState.IN_PROGRESS;
} }
EntityOperationsLogEntryPE logEntry = EntityOperationsLogEntryPE logEntry =
daoFactory.getEntityOperationsLogDAO().tryFindLogEntry(registrationId.getId()); daoFactory.getEntityOperationsLogDAO().tryFindLogEntry(registrationId.getId());
return logEntry != null;
if (logEntry != null)
{
return EntityOperationsState.OPERATION_SUCCEEDED;
} else
{
return EntityOperationsState.NO_OPERATION;
}
} }
private List<Space> createSpaces(Session session, private List<Space> createSpaces(Session session,
......
...@@ -31,6 +31,7 @@ import ch.systemsx.cisd.common.spring.IInvocationLoggerContext; ...@@ -31,6 +31,7 @@ import ch.systemsx.cisd.common.spring.IInvocationLoggerContext;
import ch.systemsx.cisd.openbis.generic.shared.AbstractServerLogger; import ch.systemsx.cisd.openbis.generic.shared.AbstractServerLogger;
import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService; import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.EntityOperationsState;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus;
...@@ -647,7 +648,7 @@ public class ETLServiceLogger extends AbstractServerLogger implements IETLLIMSSe ...@@ -647,7 +648,7 @@ public class ETLServiceLogger extends AbstractServerLogger implements IETLLIMSSe
} }
@Override @Override
public Boolean didEntityOperationsSucceed(String token, TechId registrationId) public EntityOperationsState didEntityOperationsSucceed(String token, TechId registrationId)
{ {
logAccess(Level.DEBUG, token, "didEntityOperationsSucceed", "REGISTRATION_ID(%s)", logAccess(Level.DEBUG, token, "didEntityOperationsSucceed", "REGISTRATION_ID(%s)",
registrationId); registrationId);
......
/*
* Copyright 2012 ETH Zuerich, CISD
*
* 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 ch.systemsx.cisd.openbis.generic.server;
import java.util.HashSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
/**
* The application state of all entity operations that are currently in progress.
*
* @author jakubs
*/
public class EntityOperationsInProgress
{
private static EntityOperationsInProgress instance;
private static Object locker = new Object();
/**
* The singleton
*/
public static EntityOperationsInProgress getInstance()
{
if (instance == null)
{
synchronized (locker)
{
if (instance == null)
{
instance = new EntityOperationsInProgress();
}
}
}
return instance;
}
private final HashSet<TechId> pendingRegistrations;
private EntityOperationsInProgress()
{
pendingRegistrations = new HashSet<TechId>();
}
/**
* Check whether the registration with given id is being processed right now.
*/
public boolean isRegistrationPending(TechId id)
{
if (id == null)
{
throw new IllegalArgumentException("Cannot ask if a registration is pending for null");
}
synchronized (locker)
{
return pendingRegistrations.contains(id);
}
}
/**
* Mark given id as being processed.
*/
public void addRegistrationPending(TechId id)
{
if (id != null)
{
synchronized (locker)
{
pendingRegistrations.add(id);
}
}
}
/**
* Remove the given registration id from the being processed list.
*/
public void removeRegistrationPending(TechId id)
{
if (id != null)
{
synchronized (locker)
{
pendingRegistrations.remove(id);
}
}
}
}
...@@ -47,6 +47,7 @@ import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleUpd ...@@ -47,6 +47,7 @@ import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleUpd
import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SpaceIdentifierPredicate; import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SpaceIdentifierPredicate;
import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.ProjectValidator; import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.ProjectValidator;
import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.SampleValidator; import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.SampleValidator;
import ch.systemsx.cisd.openbis.generic.shared.basic.EntityOperationsState;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus;
...@@ -801,5 +802,5 @@ public interface IETLLIMSService extends IServer, ISessionProvider, Conversation ...@@ -801,5 +802,5 @@ public interface IETLLIMSService extends IServer, ISessionProvider, Conversation
*/ */
@Transactional(readOnly = true) @Transactional(readOnly = true)
@RolesAllowed(RoleWithHierarchy.SPACE_ETL_SERVER) @RolesAllowed(RoleWithHierarchy.SPACE_ETL_SERVER)
public Boolean didEntityOperationsSucceed(String token, TechId registrationId); public EntityOperationsState didEntityOperationsSucceed(String token, TechId registrationId);
} }
/*
* Copyright 2012 ETH Zuerich, CISD
*
* 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 ch.systemsx.cisd.openbis.generic.shared.basic;
/**
* The state of the entity operations registration process.
*
* @author jakubs
*/
public enum EntityOperationsState
{
/**
* Neither succeeded, nor in progress
*/
NO_OPERATION,
/**
* Operations succeeded
*/
OPERATION_SUCCEEDED,
/**
* Operation in progress
*/
IN_PROGRESS
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment