aepp 0.4.0.post2__py3-none-any.whl → 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aepp/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.4.0-2"
1
+ __version__ = "0.4.1"
aepp/classmanager.py CHANGED
@@ -4,6 +4,7 @@ import aepp
4
4
  from .configs import ConnectObject
5
5
  from aepp.schema import Schema
6
6
  import pandas as pd
7
+ import numpy as np
7
8
  from copy import deepcopy
8
9
  from io import FileIO
9
10
  from pathlib import Path
@@ -451,11 +452,7 @@ class ClassManager:
451
452
  res,foundFlag = self.__setField__(completePathList,fieldGroup[key]['properties'],newField,obj)
452
453
  fieldGroup[key]['properties'] = res
453
454
  else:
454
- if newField in fieldGroup[key]['properties'].keys():
455
- fieldGroup[key]['properties'][newField]['title'] = obj["title"]
456
- fieldGroup[key]['properties'][newField]['description'] = obj["description"]
457
- else:
458
- fieldGroup[key]['properties'][newField] = obj
455
+ fieldGroup[key]['properties'][newField] = obj
459
456
  foundFlag = True
460
457
  return fieldGroup,foundFlag
461
458
  elif 'items' in level.keys():
@@ -464,11 +461,7 @@ class ClassManager:
464
461
  res, foundFlag = self.__setField__(completePathList,fieldGroup[key]['items']['properties'],newField,obj)
465
462
  fieldGroup[key]['items']['properties'] = res
466
463
  else:
467
- if newField in fieldGroup[key]['items']['properties'].keys():
468
- fieldGroup[key]['items']['properties'][newField]['title'] = obj['title']
469
- fieldGroup[key]['items']['properties'][newField]['description'] = obj['description']
470
- else:
471
- fieldGroup[key]['items']['properties'][newField] = obj
464
+ fieldGroup[key]['items']['properties'][newField] = obj
472
465
  foundFlag = True
473
466
  return fieldGroup,foundFlag
474
467
  return fieldGroup,foundFlag
@@ -504,9 +497,16 @@ class ClassManager:
504
497
  return success
505
498
  return success
506
499
 
507
- def __transformFieldType__(self,dataType:str=None)->dict:
500
+ def __transformFieldType__(self,dataType:str=None,**kwargs)->dict:
508
501
  """
509
502
  return the object with the type and possible meta attribute.
503
+ possible kwargs:
504
+ minimum : minimum value for number/integer
505
+ maximum : maximum value for number/integer
506
+ pattern : pattern for string
507
+ minLength : minimum length for string
508
+ maxLength : maximum length for string
509
+ default : default value for the field
510
510
  """
511
511
  obj = {}
512
512
  if dataType == 'double':
@@ -531,6 +531,10 @@ class ClassManager:
531
531
  obj['minimum'] = -128
532
532
  else:
533
533
  obj['type'] = dataType
534
+ list_possible_kwargs = ['minimum','maximum','pattern','minLength','maxLength','enum','default']
535
+ for kw in kwargs:
536
+ if kw in list_possible_kwargs:
537
+ obj[kw] = kwargs[kw]
534
538
  return obj
535
539
 
536
540
  def __transformationDict__(self,mydict:dict=None,typed:bool=False,dictionary:dict=None)->dict:
@@ -651,9 +655,8 @@ class ClassManager:
651
655
  dictionary:dict=None,
652
656
  path:str=None,
653
657
  queryPath:bool=False,
654
- description:bool=False,
655
- xdmType:bool=False,
656
- required:bool=False)->dict:
658
+ required:bool=False,
659
+ full:bool=False)->dict:
657
660
  """
658
661
  Transform the current XDM schema to a dictionary.
659
662
  Arguments:
@@ -664,15 +667,21 @@ class ClassManager:
664
667
  description : boolean to tell if you want to retrieve the description
665
668
  xdmType : boolean to know if you want to retrieve the xdm Type
666
669
  required : boolean to know if you want to retrieve the required fields
670
+ full : boolean : to know if you want to retrieve all the information (minLength, etc)
667
671
  """
668
672
  if dictionary is None:
669
- dictionary = {'path':[],'type':[],'title':[]}
670
- if queryPath:
673
+ dictionary = {'path':[],'type':[],'title':[],'description':[],'xdmType':[],'mapType':[]}
674
+ if queryPath or full:
671
675
  dictionary['querypath'] = []
672
- if description:
673
- dictionary['description'] = []
674
- if xdmType:
675
- dictionary['xdmType'] = []
676
+ if full:
677
+ dictionary['minLength'] = []
678
+ dictionary['maxLength'] = []
679
+ dictionary['minimum'] = []
680
+ dictionary['maximum'] = []
681
+ dictionary['pattern'] = []
682
+ dictionary['enumValues'] = []
683
+ dictionary['enum'] = []
684
+ dictionary['default'] = []
676
685
  else:
677
686
  dictionary = dictionary
678
687
  for key in mydict:
@@ -687,14 +696,29 @@ class ClassManager:
687
696
  tmp_path = f"{path}.{key}"
688
697
  if tmp_path is not None:
689
698
  dictionary["path"].append(tmp_path)
690
- dictionary["type"].append(f"{mydict[key].get('type')}")
691
- dictionary["title"].append(f"{mydict[key].get('title')}")
692
- if queryPath:
699
+ dictionary["type"].append(f"{mydict[key].get('type','')}")
700
+ dictionary["title"].append(f"{mydict[key].get('title','')}")
701
+ dictionary["description"].append(f"{mydict[key].get('description','')}")
702
+ dictionary["xdmType"].append(f"{mydict[key].get('meta:xdmType','')}")
703
+ if mydict[key].get('meta:xdmType') == 'map':
704
+ dictionary["mapType"].append(f"{mydict[key].get('additionalProperties',{}).get('type','string')}")
705
+ else:
706
+ dictionary["mapType"].append(pd.NA)
707
+ if queryPath or full:
693
708
  dictionary["querypath"].append(self.__cleanPath__(tmp_path))
694
- if description:
695
- dictionary["description"].append(f"{mydict[key].get('description','')}")
696
- if xdmType:
697
- dictionary["xdmType"].append(f"{mydict[key].get('meta:xdmType')}")
709
+ if full:
710
+ dictionary['minLength'].append(mydict[key].get('minLength',np.nan))
711
+ dictionary['maxLength'].append(mydict[key].get('maxLength',np.nan))
712
+ dictionary['minimum'].append(mydict[key].get('minimum',np.nan))
713
+ dictionary['maximum'].append(mydict[key].get('maximum',np.nan))
714
+ dictionary['pattern'].append(mydict[key].get('pattern',pd.NA))
715
+ dictionary['default'].append(mydict[key].get('default',pd.NA))
716
+ enumValues = mydict[key].get('meta:enum',pd.NA)
717
+ dictionary['enumValues'].append(enumValues)
718
+ if len(mydict[key].get('enum',[])) > 0:
719
+ dictionary['enum'].append(True)
720
+ else:
721
+ dictionary['enum'].append(False)
698
722
  if required:
699
723
  if len(mydict[key].get('required',[])) > 0:
700
724
  for elRequired in mydict[key].get('required',[]):
@@ -705,7 +729,7 @@ class ClassManager:
705
729
  self.requiredFields.add(tmp_reqPath)
706
730
  properties = mydict[key].get('properties',None)
707
731
  if properties is not None:
708
- self.__transformationDF__(properties,dictionary,tmp_path,queryPath,description,xdmType,required)
732
+ self.__transformationDF__(properties,dictionary,tmp_path,queryPath,required,full=full)
709
733
  elif mydict[key].get('type') == 'array':
710
734
  levelProperties = mydict[key]['items'].get('properties',None)
711
735
  if levelProperties is not None: ## array of objects
@@ -715,13 +739,28 @@ class ClassManager:
715
739
  tmp_path = f"{path}.{key}[]{{}}"
716
740
  dictionary["path"].append(tmp_path)
717
741
  dictionary["type"].append(f"{mydict[key].get('type')}")
718
- dictionary["title"].append(f"{mydict[key].get('title')}")
719
- if queryPath and tmp_path is not None:
742
+ dictionary["title"].append(f"{mydict[key].get('title','')}")
743
+ dictionary["description"].append(mydict[key].get('description',''))
744
+ dictionary["xdmType"].append(f"{mydict[key].get('meta:xdmType','')}")
745
+ if mydict[key].get('meta:xdmType') == 'map':
746
+ dictionary["mapType"].append(f"{mydict[key].get('additionalProperties',{}).get('type','string')}")
747
+ else:
748
+ dictionary["mapType"].append(pd.NA)
749
+ if (queryPath or full) and tmp_path is not None:
720
750
  dictionary["querypath"].append(self.__cleanPath__(tmp_path))
721
- if description and tmp_path is not None:
722
- dictionary["description"].append(mydict[key].get('description',''))
723
- if xdmType:
724
- dictionary["xdmType"].append(f"{mydict[key].get('meta:xdmType')}")
751
+ if full:
752
+ dictionary['minLength'].append(mydict[key].get('minLength',np.nan))
753
+ dictionary['maxLength'].append(mydict[key].get('maxLength',np.nan))
754
+ dictionary['minimum'].append(mydict[key].get('minimum',np.nan))
755
+ dictionary['maximum'].append(mydict[key].get('maximum',np.nan))
756
+ dictionary['pattern'].append(mydict[key].get('pattern',pd.NA))
757
+ dictionary['default'].append(mydict[key].get('default',pd.NA))
758
+ enumValues = mydict[key].get('meta:enum',pd.NA)
759
+ dictionary['enumValues'].append(enumValues)
760
+ if len(mydict[key].get('enum',[])) > 0:
761
+ dictionary['enum'].append(True)
762
+ else:
763
+ dictionary['enum'].append(False)
725
764
  if required:
726
765
  if len(mydict[key].get('required',[])) > 0:
727
766
  for elRequired in mydict[key].get('required',[]):
@@ -730,21 +769,36 @@ class ClassManager:
730
769
  else:
731
770
  tmp_reqPath = f"{elRequired}"
732
771
  self.requiredFields.add(tmp_reqPath)
733
- self.__transformationDF__(levelProperties,dictionary,tmp_path,queryPath,description,xdmType,required)
772
+ self.__transformationDF__(levelProperties,dictionary,tmp_path,queryPath,required,full=full)
734
773
  else: ## simple arrays
735
774
  if path is None:
736
775
  finalpath = f"{key}[]"
737
776
  else:
738
777
  finalpath = f"{path}.{key}[]"
739
778
  dictionary["path"].append(finalpath)
740
- dictionary["type"].append(f"{mydict[key]['items'].get('type')}[]")
741
- dictionary["title"].append(f"{mydict[key].get('title')}")
742
- if queryPath and finalpath is not None:
779
+ dictionary["type"].append(f"{mydict[key]['items'].get('type','')}[]")
780
+ dictionary["title"].append(f"{mydict[key].get('title','')}")
781
+ dictionary["description"].append(mydict[key].get('description',''))
782
+ dictionary["xdmType"].append(mydict[key]['items'].get('meta:xdmType',''))
783
+ if mydict[key]['items'].get('meta:xdmType') == 'map':
784
+ dictionary["mapType"].append(f"{mydict[key]['items'].get('additionalProperties',{}).get('type','string')}")
785
+ else:
786
+ dictionary["mapType"].append(pd.NA)
787
+ if queryPath or full:
743
788
  dictionary["querypath"].append(self.__cleanPath__(finalpath))
744
- if description and finalpath is not None:
745
- dictionary["description"].append(mydict[key].get('description',''))
746
- if xdmType:
747
- dictionary["xdmType"].append(mydict[key]['items'].get('meta:xdmType',''))
789
+ if full:
790
+ dictionary['minLength'].append(mydict[key]['items'].get('minLength',np.nan))
791
+ dictionary['maxLength'].append(mydict[key]['items'].get('maxLength',np.nan))
792
+ dictionary['minimum'].append(mydict[key]['items'].get('minimum',np.nan))
793
+ dictionary['maximum'].append(mydict[key]['items'].get('maximum',np.nan))
794
+ dictionary['pattern'].append(mydict[key]['items'].get('pattern',np.nan))
795
+ dictionary['default'].append(mydict[key]['items'].get('default',np.nan))
796
+ enumValues = mydict[key]['items'].get('meta:enum',pd.NA)
797
+ dictionary['enumValues'].append(enumValues)
798
+ if len(mydict[key]['items'].get('enum',[])) > 0:
799
+ dictionary['enum'].append(True)
800
+ else:
801
+ dictionary['enum'].append(False)
748
802
  if required:
749
803
  if len(mydict[key].get('required',[])) > 0:
750
804
  for elRequired in mydict[key].get('required',[]):
@@ -758,12 +812,27 @@ class ClassManager:
758
812
  dictionary["path"].append(finalpath)
759
813
  dictionary["type"].append(mydict[key].get('type','object'))
760
814
  dictionary["title"].append(mydict[key].get('title',''))
761
- if queryPath and finalpath is not None:
815
+ dictionary["description"].append(mydict[key].get('description',''))
816
+ dictionary["xdmType"].append(mydict[key].get('meta:xdmType',''))
817
+ if mydict[key].get('meta:xdmType') == 'map':
818
+ dictionary["mapType"].append(f"{mydict[key].get('additionalProperties',{}).get('type','string')}")
819
+ else:
820
+ dictionary["mapType"].append(pd.NA)
821
+ if queryPath or full:
762
822
  dictionary["querypath"].append(self.__cleanPath__(finalpath))
763
- if description :
764
- dictionary["description"].append(mydict[key].get('description',''))
765
- if xdmType :
766
- dictionary["xdmType"].append(mydict[key].get('meta:xdmType',''))
823
+ if full:
824
+ dictionary['minLength'].append(mydict[key].get('minLength',np.nan))
825
+ dictionary['maxLength'].append(mydict[key].get('maxLength',np.nan))
826
+ dictionary['minimum'].append(mydict[key].get('minimum',np.nan))
827
+ dictionary['maximum'].append(mydict[key].get('maximum',np.nan))
828
+ dictionary['pattern'].append(mydict[key].get('pattern',pd.NA))
829
+ dictionary['default'].append(mydict[key].get('default',pd.NA))
830
+ enumValues = mydict[key].get('meta:enum',pd.NA)
831
+ dictionary['enumValues'].append(enumValues)
832
+ if len(mydict[key].get('enum',[])) > 0:
833
+ dictionary['enum'].append(True)
834
+ else:
835
+ dictionary['enum'].append(False)
767
836
  if required:
768
837
  if len(mydict[key].get('required',[])) > 0:
769
838
  for elRequired in mydict[key].get('required',[]):
@@ -857,6 +926,12 @@ class ClassManager:
857
926
  possible kwargs:
858
927
  defaultPath : Define which path to take by default for adding new field on tenant. Default "customFields", possible alternative : "property"
859
928
  description : if you want to add a description on your field
929
+ maximum : if you want to add a maximum value for numeric field
930
+ minimum : if you want to add a minimum value for numeric field
931
+ pattern : if you want to add a pattern for string field
932
+ minLength : if you want to add a minimum length for string field
933
+ maxLength : if you want to add a maximum length for string field
934
+ default : if you want to add a default value for the field
860
935
  """
861
936
  if self.EDITABLE == False:
862
937
  raise Exception("The Field Group is not Editable via Field Group Manager")
@@ -916,14 +991,20 @@ class ClassManager:
916
991
  "title":title
917
992
  }
918
993
  else:
919
- obj = self.__transformFieldType__(dataType)
994
+ minimum = kwargs.get('minimum',None)
995
+ maximum = kwargs.get('maximum',None)
996
+ pattern = kwargs.get('pattern',None)
997
+ minLength = kwargs.get('minLength',None)
998
+ maxLength = kwargs.get('maxLength',None)
999
+ default = kwargs.get('default',None)
1000
+ obj = self.__transformFieldType__(dataType,minimum=minimum,maximum=maximum,pattern=pattern,minLength=minLength,maxLength=maxLength,default=default)
920
1001
  obj['title'] = title
921
1002
  obj["description"] = description,
922
1003
  if type(obj["description"]) == tuple:
923
1004
  obj["description"] = obj["description"][0]
924
1005
  if array:
925
1006
  obj['type'] = "array"
926
- obj['items'] = self.__transformFieldType__(dataType)
1007
+ obj['items'] = self.__transformFieldType__(dataType,minimum=minimum,maximum=maximum,pattern=pattern,minLength=minLength,maxLength=maxLength,default=default)
927
1008
  if enumValues is not None and type(enumValues) == dict:
928
1009
  if array == False:
929
1010
  obj['meta:enum'] = enumValues
@@ -987,28 +1068,28 @@ class ClassManager:
987
1068
  xdmType:bool=True,
988
1069
  editable:bool=False,
989
1070
  excludeObjects:bool=False,
990
- required:bool=False)->pd.DataFrame:
1071
+ required:bool=False,
1072
+ full:bool=False)->pd.DataFrame:
991
1073
  """
992
1074
  Generate a dataframe with the row representing each possible path.
993
1075
  Arguments:
994
1076
  save : OPTIONAL : If you wish to save it with the title used by the field group.
995
1077
  save as csv with the title used. Not title, used "unknown_fieldGroup_" + timestamp.
996
1078
  queryPath : OPTIONAL : If you want to have the query path to be used.
997
- description : OPTIONAL : If you want to have the description used (default False)
998
- xdmType : OPTIONAL : If you want to have the xdmType also returned (default True)
999
1079
  editable : OPTIONAL : If you can manipulate the structure of the field groups (default False)
1000
1080
  excludeObjects : OPTIONAL : Remove the fields that are noted down as object so only fields containing data are returned.
1001
1081
  required : OPTIONAL : If you want to have the required field in the dataframe (default False)
1082
+ full : OPTIONAL : If you want to have all the possible attributes (minLength, maxLength, pattern, enum, default) in the dataframe (default False)
1002
1083
  """
1003
1084
  definition = self.aepclass.get('definitions',self.aepclass.get('properties',{}))
1004
- data = self.__transformationDF__(definition,queryPath=queryPath,description=description,xdmType=xdmType,required=required)
1085
+ data = self.__transformationDF__(definition,queryPath=queryPath,required=required,full=full)
1005
1086
  df = pd.DataFrame(data)
1006
1087
  df = df[~df.path.duplicated()].copy() ## dedup the paths
1007
1088
  df = df[~(df['path']==self.tenantId)].copy()## remove the root
1008
1089
  df['origin'] = 'class'
1009
1090
  if self.EDITABLE:
1010
1091
  behaviorDefinition = self.behaviorDefinition.get('properties')
1011
- dataBehavior = self.__transformationDF__(behaviorDefinition,queryPath=queryPath,description=description,xdmType=xdmType,required=required)
1092
+ dataBehavior = self.__transformationDF__(behaviorDefinition,queryPath=queryPath,required=required,full=full)
1012
1093
  dfBehavior = pd.DataFrame(dataBehavior)
1013
1094
  dfBehavior['origin'] = 'class behavior'
1014
1095
  df = pd.concat([df,dfBehavior],axis=0,ignore_index=True)
aepp/connector.py CHANGED
@@ -250,7 +250,10 @@ class AdobeRequest:
250
250
  endpoint = f"{self.endpoints['global']}{self.endpoints['sandboxes']}/sandboxes/{sandbox}"
251
251
  res = self.getData(endpoint)
252
252
  if "id" not in res:
253
- raise Exception("sandbox Id not found")
253
+ error_message = res.get("message", "sandbox Id not found")
254
+ if self.loggingEnabled:
255
+ self.logger.error(f"sandbox id '{sandbox}' retrieval failed: {error_message}")
256
+ raise Exception(error_message)
254
257
  sandbox_id = res["id"]
255
258
  self.header["x-sandbox-id"] = sandbox_id
256
259