Skip to content
Snippets Groups Projects
Commit 6a4b4e3f authored by juanf's avatar juanf
Browse files

SSDM-10222 : Set storage default validation value when missing

parent 5e3fbccf
No related branches found
No related tags found
No related merge requests found
package ch.systemsx.cisd.openbis.generic.server.hotfix;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.Sample;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.fetchoptions.SampleFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.search.SampleSearchCriteria;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.update.SampleUpdate;
import ch.ethz.sis.openbis.generic.server.asapi.v3.IApplicationServerInternalApi;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
public class ELNFixes {
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, ELNAnnotationsMigration.class);
public static void beforeUpgrade() throws Exception {
operationLog.info("ELNFixes beforeUpgrade START");
IApplicationServerInternalApi api = CommonServiceProvider.getApplicationServerApi();
String sessionToken = api.loginAsSystem();
storageValidationLevelFix(sessionToken, api);
}
private static final String STORAGE_VALIDATION_LEVEL_PROPERTY_CODE = "$STORAGE.STORAGE_VALIDATION_LEVEL";
private static final String STORAGE_VALIDATION_LEVEL_DEFAULT_VALUE = "RACK";
private static void storageValidationLevelFix(String sessionToken, IApplicationServerInternalApi api) {
SampleSearchCriteria criteria = new SampleSearchCriteria();
criteria.withType().withCode().thatEquals("STORAGE");
SampleFetchOptions options = new SampleFetchOptions();
options.withProperties();
SearchResult<Sample> storages = api.searchSamples(sessionToken, criteria, options);
List<SampleUpdate> storageUpdates = new ArrayList<>();
for (Sample storage:storages.getObjects()) {
if(storage.getProperty(STORAGE_VALIDATION_LEVEL_PROPERTY_CODE) == null ||
storage.getProperty(STORAGE_VALIDATION_LEVEL_PROPERTY_CODE).isEmpty()) {
SampleUpdate storageUpdate = new SampleUpdate();
storageUpdate.setSampleId(storage.getPermId());
storageUpdate.setProperty(STORAGE_VALIDATION_LEVEL_PROPERTY_CODE, STORAGE_VALIDATION_LEVEL_DEFAULT_VALUE);
storageUpdates.add(storageUpdate);
}
}
api.updateSamples(sessionToken, storageUpdates);
}
}
...@@ -21,9 +21,11 @@ from ch.ethz.sis.openbis.generic.asapi.v3.dto.service import CustomASServiceExec ...@@ -21,9 +21,11 @@ from ch.ethz.sis.openbis.generic.asapi.v3.dto.service import CustomASServiceExec
from ch.systemsx.cisd.openbis.generic.server.jython.api.v1.impl import MasterDataRegistrationHelper from ch.systemsx.cisd.openbis.generic.server.jython.api.v1.impl import MasterDataRegistrationHelper
import sys import sys
from ch.systemsx.cisd.openbis.generic.server.hotfix import ELNFixes
from ch.systemsx.cisd.openbis.generic.server.hotfix import ELNAnnotationsMigration from ch.systemsx.cisd.openbis.generic.server.hotfix import ELNAnnotationsMigration
from ch.systemsx.cisd.openbis.generic.server.hotfix import ELNCollectionTypeMigration from ch.systemsx.cisd.openbis.generic.server.hotfix import ELNCollectionTypeMigration
ELNFixes.beforeUpgrade()
ELNAnnotationsMigration.beforeUpgrade() ELNAnnotationsMigration.beforeUpgrade()
ELNCollectionTypeMigration.beforeUpgrade() ELNCollectionTypeMigration.beforeUpgrade()
......
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