Skip to content

Commit d5300f1

Browse files
LennartSchmidtKernlumburovskalinaandhreljaKern
authored
Add text list attribute for sharepoint integration tags (#179)
* datatypes attribute text list * payload selector * IntegrationSharepointPropertySync * schema * get update sync properties * Syntax fix * import fix * proeprt sync state * chore: add extension TODO comment * get by running ids * perf: move sharepoint property sync into cognition objects * perf: move create function into cognition objects * perf: SYNC_SHAREPOINT_FILE_PROPERTIES task * perf: add sync_finished for task-master * perf: remove extra task type * perf: remove extra task type * perf: remove unused FINISHED_STATES --------- Co-authored-by: Lina <[email protected]> Co-authored-by: andhreljaKern <[email protected]>
1 parent b051680 commit d5300f1

File tree

6 files changed

+100
-2
lines changed

6 files changed

+100
-2
lines changed

business_objects/embedding.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,13 @@ def __build_payload_selector(
321321
data_type != enums.DataTypes.TEXT.value
322322
and data_type != enums.DataTypes.LLM_RESPONSE.value
323323
and data_type != enums.DataTypes.PERMISSION.value
324+
and data_type != enums.DataTypes.TEXT_LIST.value
324325
):
325326
payload_selector += f"'{attr}', (r.\"data\"->>'{attr}')::{data_type}"
326-
elif data_type == enums.DataTypes.PERMISSION.value:
327+
elif (
328+
data_type == enums.DataTypes.PERMISSION.value
329+
or data_type == enums.DataTypes.TEXT_LIST.value
330+
):
327331
payload_selector += f"'{attr}', r.\"data\"->'{attr}'"
328332
else:
329333
payload_selector += f"'{attr}', r.\"data\"->>'{attr}'"

business_objects/record.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ def get_first_no_text_column(project_id: str, record_id: str) -> str:
943943
(
944944
SELECT a.name
945945
FROM attribute a
946-
WHERE data_type NOT IN('{enums.DataTypes.TEXT.value}' , '{enums.DataTypes.CATEGORY.value}', '{enums.DataTypes.LLM_RESPONSE.value}')
946+
WHERE data_type NOT IN('{enums.DataTypes.TEXT.value}', '{enums.DataTypes.CATEGORY.value}', '{enums.DataTypes.LLM_RESPONSE.value}', '{enums.DataTypes.TEXT_LIST.value}')
947947
AND a.state IN ('{enums.AttributeState.AUTOMATICALLY_CREATED.value}','{enums.AttributeState.UPLOADED.value}','{enums.AttributeState.USABLE.value}')
948948
AND a.project_id = '{project_id}'
949949
ORDER BY a.relative_position
@@ -968,3 +968,16 @@ def get_record_ids_by_running_ids(project_id: str, running_ids: List[int]) -> Li
968968
.all()
969969
)
970970
]
971+
972+
973+
def get_records_by_running_ids(project_id: str, running_ids: List[int]) -> List[str]:
974+
return (
975+
session.query(Record)
976+
.filter(
977+
Record.project_id == project_id,
978+
Record.data[attribute.get_running_id_name(project_id)]
979+
.as_integer()
980+
.in_(running_ids),
981+
)
982+
.all()
983+
)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from typing import List, Optional, Dict, Any
2+
from sqlalchemy.orm.attributes import flag_modified
3+
from ..models import IntegrationSharepointPropertySync
4+
from ..enums import SharepointPropertySyncState
5+
from ..business_objects import general
6+
from ..session import session
7+
8+
9+
def get_by_integration_id(
10+
integration_id: str,
11+
) -> IntegrationSharepointPropertySync:
12+
return (
13+
session.query(IntegrationSharepointPropertySync)
14+
.filter(IntegrationSharepointPropertySync.integration_id == integration_id)
15+
.first()
16+
)
17+
18+
19+
def create(
20+
integration_id: str,
21+
config: Optional[Dict[str, Any]] = None,
22+
logs: Optional[List[Dict[str, Any]]] = None,
23+
with_commit: bool = True,
24+
) -> IntegrationSharepointPropertySync:
25+
integration_sync = IntegrationSharepointPropertySync(
26+
integration_id=integration_id,
27+
config=config or {},
28+
logs=logs or [],
29+
)
30+
session.add(integration_sync)
31+
general.flush_or_commit(with_commit)
32+
return integration_sync
33+
34+
35+
def update(
36+
integration_id: str,
37+
config: Optional[Dict[str, Any]] = None,
38+
logs: Optional[List[Dict[str, Any]]] = None,
39+
with_commit: bool = True,
40+
) -> IntegrationSharepointPropertySync:
41+
integration_sync = get_by_integration_id(integration_id)
42+
if config is not None:
43+
integration_sync.config = config
44+
flag_modified(integration_sync, "config")
45+
if logs is not None:
46+
integration_sync.logs = logs
47+
flag_modified(integration_sync, "logs")
48+
general.flush_or_commit(with_commit)
49+
return integration_sync

enums.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class DataTypes(Enum):
1111
LLM_RESPONSE = "LLM_RESPONSE"
1212
EMBEDDING_LIST = "EMBEDDING_LIST" # only for embeddings & default hidden
1313
PERMISSION = "PERMISSION" # used for access control
14+
TEXT_LIST = "TEXT_LIST"
1415
UNKNOWN = "UNKNOWN"
1516

1617

@@ -168,6 +169,7 @@ class Tablenames(Enum):
168169
INTEGRATION_PDF = "pdf"
169170
INTEGRATION_SHAREPOINT = "sharepoint"
170171
STEP_TEMPLATES = "step_templates" # templates for strategy steps
172+
INTEGRATION_SHAREPOINT_PROPERTY_SYNC = "sharepoint_property_sync"
171173
CONVERSATION_TAG = "conversation_tag" # config of tags used in conversations
172174
CONVERSATION_TAG_ASSOCIATION = (
173175
"conversation_tag_association" # association between conversation and tags
@@ -946,3 +948,10 @@ def from_string(value: str):
946948
raise KeyError(
947949
f"Could not parse CognitionIntegrationType from string '{changed_value}'"
948950
)
951+
952+
953+
class SharepointPropertySyncState(Enum):
954+
CREATED = "CREATED"
955+
RUNNING = "RUNNING"
956+
COMPLETED = "COMPLETED"
957+
FAILED = "FAILED"

integration_objects/manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def get_existing_integration_records(
9292
integration_id: str,
9393
by: str = "source",
9494
) -> Dict[str, object]:
95+
# TODO(extension): make return type Dict[str, List[object]]
96+
# once an object_id can reference multiple different integration records
9597
return {
9698
getattr(record, by, record.source): record
9799
for record in get_all_by_integration_id(IntegrationModel, integration_id)

models.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,27 @@ class IntegrationSharepoint(Base):
23902390
file_properties = Column(JSON)
23912391

23922392

2393+
class IntegrationSharepointPropertySync(Base):
2394+
__tablename__ = Tablenames.INTEGRATION_SHAREPOINT_PROPERTY_SYNC.value
2395+
__table_args__ = (UniqueConstraint("integration_id"), {"schema": "integration"})
2396+
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
2397+
created_by = Column(
2398+
UUID(as_uuid=True),
2399+
ForeignKey(f"{Tablenames.USER.value}.id", ondelete="SET NULL"),
2400+
index=True,
2401+
)
2402+
created_at = Column(DateTime, default=sql.func.now())
2403+
updated_at = Column(DateTime, onupdate=sql.func.now())
2404+
integration_id = Column(
2405+
UUID(as_uuid=True),
2406+
ForeignKey(f"cognition.{Tablenames.INTEGRATION.value}.id", ondelete="CASCADE"),
2407+
index=True,
2408+
)
2409+
config = Column(JSON) # JSON object containing the rules for property sync
2410+
logs = Column(ARRAY(String))
2411+
state = Column(String)
2412+
2413+
23932414
class CognitionConversationTag(Base):
23942415
__tablename__ = Tablenames.CONVERSATION_TAG.value
23952416
__table_args__ = {"schema": "cognition"}

0 commit comments

Comments
 (0)