<commit_before># -*- coding: utf-8 -*-
import ch.systemsx.cisd.openbis.generic.server.jython.api.v1.DataType as DataType
import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider as CommonServiceProvider
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.search.ExperimentTypeSearchCriteria as ExperimentTypeSearchCriteria
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.fetchoptions.ExperimentTypeFetchOptions as ExperimentTypeFetchOptions
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.update.ExperimentTypeUpdate as ExperimentTypeUpdate
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId as EntityTypePermId
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.EntityKind as EntityKind
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.create.PropertyAssignmentCreation as PropertyAssignmentCreation
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.id.PropertyTypePermId as PropertyTypePermId
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.id.PropertyAssignmentPermId as PropertyAssignmentPermId


# Get a session token to be used to update existing properties via the V3 API
sessionToken = CommonServiceProvider.getCommonServer().tryToAuthenticateAsSystem().getSessionToken()
v3api = CommonServiceProvider.getApplicationServerApi()

searchCriteria = ExperimentTypeSearchCriteria()
searchCriteria.withCode().thatEquals("MICROSCOPY_EXPERIMENT")
fetchOptions = ExperimentTypeFetchOptions()
if v3api.searchExperimentTypes(sessionToken, searchCriteria, fetchOptions).getTotalCount() > 0:
    print ("Update: Allowing editing of microscopy experiment names...")
    update = ExperimentTypeUpdate()
    typeId = EntityTypePermId("MICROSCOPY_EXPERIMENT", EntityKind.EXPERIMENT)
    update.setTypeId(typeId)
    assignmentCreation = PropertyAssignmentCreation()
    propertyTypeId = PropertyTypePermId("MICROSCOPY_EXPERIMENT_NAME")
    assignmentCreation.setPropertyTypeId(propertyTypeId)
    assignmentCreation.setShowInEditView(True)
    update.getPropertyAssignments().remove(PropertyAssignmentPermId(typeId, propertyTypeId));
    update.getPropertyAssignments().add(assignmentCreation)
    v3api.updateExperimentTypes(sessionToken, [update])

print ("Importing Microscopy Core Technology Master Data...")

tr = service.transaction()

# ==============================================================================
#
# FILE FORMATS
#
# ==============================================================================

# JPG file format
file_type_JPG = tr.getOrCreateNewFileFormatType('JPG')
file_type_JPG.setDescription(None)

# PNG file format
file_type_PNG = tr.getOrCreateNewFileFormatType('PNG')
file_type_PNG.setDescription(None)

# UNKNOWN file format
file_type_UNKNOWN = tr.getOrCreateNewFileFormatType('UNKNOWN')
file_type_UNKNOWN.setDescription('Unknown file format')

# ==============================================================================
#
# MICROSCOPY
#<commit_msg>Fix issue with updating property assignments in master data.<commit_after># -*- coding: utf-8 -*-
import ch.systemsx.cisd.openbis.generic.server.jython.api.v1.DataType as DataType
import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider as CommonServiceProvider
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.search.ExperimentTypeSearchCriteria as ExperimentTypeSearchCriteria
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.fetchoptions.ExperimentTypeFetchOptions as ExperimentTypeFetchOptions
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.update.ExperimentTypeUpdate as ExperimentTypeUpdate
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId as EntityTypePermId
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.EntityKind as EntityKind
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.create.PropertyAssignmentCreation as PropertyAssignmentCreation
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.id.PropertyTypePermId as PropertyTypePermId


# Get a session token to be used to update existing properties via the V3 API
sessionToken = CommonServiceProvider.getCommonServer().tryToAuthenticateAsSystem().getSessionToken()
v3api = CommonServiceProvider.getApplicationServerApi()

searchCriteria = ExperimentTypeSearchCriteria()
searchCriteria.withCode().thatEquals("MICROSCOPY_EXPERIMENT")
fetchOptions = ExperimentTypeFetchOptions()
if v3api.searchExperimentTypes(sessionToken, searchCriteria, fetchOptions).getTotalCount() > 0:
    print ("Update: Allowing editing of microscopy experiment names...")
    update = ExperimentTypeUpdate()
    typeId = EntityTypePermId("MICROSCOPY_EXPERIMENT", EntityKind.EXPERIMENT)
    update.setTypeId(typeId)
    assignmentCreation = PropertyAssignmentCreation()
    propertyTypeId = PropertyTypePermId("MICROSCOPY_EXPERIMENT_NAME")
    assignmentCreation.setPropertyTypeId(propertyTypeId)
    assignmentCreation.setShowInEditView(True)
    update.getPropertyAssignments().set(assignmentCreation)
    v3api.updateExperimentTypes(sessionToken, [update])

print ("Importing Microscopy Core Technology Master Data...")

tr = service.transaction()

# ==============================================================================
#
# FILE FORMATS
#
# ==============================================================================

# JPG file format
file_type_JPG = tr.getOrCreateNewFileFormatType('JPG')
file_type_JPG.setDescription(None)

# PNG file format
file_type_PNG = tr.getOrCreateNewFileFormatType('PNG')
file_type_PNG.setDescription(None)

# UNKNOWN file format
file_type_UNKNOWN = tr.getOrCreateNewFileFormatType('UNKNOWN')
file_type_UNKNOWN.setDescription('Unknown file format')

# ==============================================================================
#
# MICROSCOPY
#
{'fraction_non_alphanumeric': 0.16471600688468158, 'fraction_numerical': 0.0049913941480206545, 'mean_word_length': 7.647321428571429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '822928', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1640, 'n_words': 260}