コード例 #1
0
	def action(space: Space) -> Space:
		if space_service.is_storable_id_faked(space.spaceId):
			space_service.redress_storable_id(space)
			user_group_ids = ArrayHelper(space.groupIds).distinct().to_list()
			space.groupIds = user_group_ids
			topic_ids = ArrayHelper(space.topicIds).distinct().to_list()
			space.topicIds = topic_ids
			# check topics
			validate_topics(space_service, topic_ids, space.tenantId)
			# noinspection PyTypeChecker
			space: Space = space_service.create(space)
			# synchronize space to user groups
			sync_space_to_groups(space_service, space.spaceId, user_group_ids, space.tenantId)
		else:
			# noinspection PyTypeChecker,DuplicatedCode
			existing_space: Optional[Space] = space_service.find_by_id(space.spaceId)
			if existing_space is not None:
				if existing_space.tenantId != space.tenantId:
					raise_403()

			user_group_ids = ArrayHelper(space.groupIds).distinct().to_list()
			space.groupIds = user_group_ids
			topic_ids = ArrayHelper(space.topicIds).distinct().to_list()
			space.topicIds = topic_ids
			# check topics
			validate_topics(space_service, topic_ids, space.tenantId)
			# noinspection PyTypeChecker
			space: Space = space_service.update(space)
			# remove space from user groups, in case user groups are removed
			removed_user_group_ids = ArrayHelper(existing_space.groupIds).difference(user_group_ids).to_list()
			remove_space_from_groups(space_service, space.spaceId, removed_user_group_ids, space.tenantId)
			# synchronize space to user groups
			sync_space_to_groups(space_service, space.spaceId, user_group_ids, space.tenantId)
		return space
コード例 #2
0
    def prepare_data(self):
        data_source = DataSource(dataSourceId='1',
                                 dataSourceCode='test',
                                 dataSourceType=DataSourceType.MYSQL,
                                 host='localhost',
                                 port='3306',
                                 username='******',
                                 password='******',
                                 name='watchmen',
                                 tenantId='1')
        data_source_service = get_data_source_service(
            create_fake_principal_service())
        data_source_service.begin_transaction()
        data_source_service.create(data_source)
        data_source_service.commit_transaction()
        CacheService.data_source().put(data_source)

        topic1 = Topic(topicId='1',
                       name='topic1',
                       type=TopicType.DISTINCT,
                       kind=TopicKind.BUSINESS,
                       factors=[
                           Factor(factorId='1',
                                  name='topic1_id',
                                  type=FactorType.SEQUENCE),
                           Factor(factorId='2',
                                  name='topic1_enabled',
                                  type=FactorType.BOOLEAN)
                       ],
                       dataSourceId=data_source.dataSourceId,
                       tenantId='1')
        topic_service = get_topic_service(create_fake_principal_service())
        topic_service.begin_transaction()
        topic_service.create(topic1)
        topic_service.commit_transaction()
        CacheService.topic().put(topic1)

        space = Space(spaceId='1',
                      name='Space1',
                      topicIds=[topic1.topicId],
                      tenantId='1')
        space_service = get_space_service(create_fake_principal_service())
        space_service.begin_transaction()
        space_service.create(space)
        space_service.commit_transaction()

        connected_space = ConnectedSpace(connectId='1',
                                         name='ConnectedSpace1',
                                         spaceId=space.spaceId,
                                         isTemplate=False,
                                         userId='1',
                                         tenantId='1')
        connected_space_service = get_connected_space_service(
            create_fake_principal_service())
        connected_space_service.begin_transaction()
        connected_space_service.create(connected_space)
        connected_space_service.commit_transaction()
コード例 #3
0
 def deserialize(self, row: EntityRow) -> Space:
     # noinspection PyTypeChecker
     return TupleShaper.deserialize_tenant_based(
         row,
         Space(spaceId=row.get('space_id'),
               name=row.get('name'),
               description=row.get('description'),
               topicIds=row.get('topic_ids'),
               groupIds=row.get('group_ids'),
               filters=row.get('filters')))
コード例 #4
0
def try_to_import_space(
		space: Space, space_service: SpaceService, do_update: bool) -> SpaceImportDataResult:
	if is_blank(space.spaceId):
		space_service.redress_storable_id(space)
		space_service.create(space)
	else:
		existing_space: Optional[Space] = space_service.find_by_id(space.spaceId)
		if existing_space is None:
			space_service.create(space)
		elif do_update:
			space.version = existing_space.version
			space_service.update(space)
		else:
			return SpaceImportDataResult(
				spaceId=space.spaceId, name=space.name, passed=False, reason='Space already exists.')

	return SpaceImportDataResult(spaceId=space.spaceId, name=space.name, passed=True)
コード例 #5
0
 def set_storable_id(self, storable: Space, storable_id: SpaceId) -> Space:
     storable.spaceId = storable_id
     return storable
コード例 #6
0
	def replace_topic_id(space: Space) -> None:
		space.topicIds = ArrayHelper(space.topicIds) \
			.map(lambda x: topic_id_map.get(x) if x in topic_id_map else x).to_list()
コード例 #7
0
	def fill_space_id(space: Space) -> None:
		old_space_id = space.spaceId
		space.spaceId = space_service.generate_storable_id()
		space_id_map[old_space_id] = space.spaceId
コード例 #8
0
	def clear(space: Space) -> None:
		space.groupIds = None