
    !                    (   S r SSKJr  SSKJrJrJr  SSKJr	  SSK
Jr  SSK
Jr  SSKJr  SSKJr  SS	KJr  \	R(                  " 5       rSS
 jr        SS jr      SS jr    SS jr    SS jr    SS jrSS jr  S     SS jjrg)z6Client for interaction with Entries API CRUD DATAPLEX.    )annotations)AnyDictList)util)
exceptions)parser_extensions)parsers)labels_util)logc                   ^ SSSSSSSSSSSS	S
S.m[        [        S U R                  5       5      5      nUR                  T5      n[	        [        [        U4S jU5      5      5      $ )znCreate a sorted list of fields to be used in update_mask for Entry based on arguments provided to the command.fully_qualified_nameaspectszentry_source.resourcezentry_source.systemzentry_source.platformzentry_source.display_namezentry_source.descriptionzentry_source.labelszentry_source.create_timezentry_source.update_time)z--fully-qualified-namez--update-aspectsz--remove-aspectsz	--aspectsz--keysz--entry-source-resourcez--entry-source-systemz--entry-source-platformz--entry-source-display-namez--entry-source-descriptionz--entry-source-labelsz--entry-source-create-timez--entry-source-update-timec                &    U R                  SS5      $ )Nz--clear-z--)replace)args    ,lib/googlecloudsdk/api_lib/dataplex/entry.py<lambda>)_GetFieldsForUpdateMask.<locals>.<lambda>9   s    ckk*d3    c                   > TU    $ N )arg_namearg_name_to_fields    r   r   r   >   s    0:r   )setmapGetSpecifiedArgNamesintersectionsorted)argsargs_cleanedupdatable_argsr   s      @r   _GetFieldsForUpdateMaskr$       s    
 !7##!84!8%@$>4$>$>& 	
3T5N5N5P,
  ,,->?.		#:N
KL
 r   c               .   [        5       nU R                  U5      (       a5  UR                  [        S U R	                  U5      R
                  5      5        U R                  U5      (       a   UR                  U R	                  U5      5        [        U5      $ )a  Generate a list of unique aspect keys to be updated or removed.

This will be used along with the update_mask for updating an Entry. This list
is populated based on `--update-aspects` and `--remove-aspects` arguments
(or `--aspects` in case of specialized command like `update-aspects`).

Args:
  args: The arguments provided to the command.
  remove_aspects_arg_name: The name of the argument that contains the aspect
    keys to be removed.
  update_aspects_arg_name: The name of the argument that contains aspect
    contents to be added or updated.

Returns:
  A sorted list of unique aspect keys to be updated or removed. Or empty list
  if neither `--update-aspects`, `--remove-aspects` or `--aspects` are
  provided to the command.
c                    U R                   $ r   )key)aspects    r   r   %_GenerateAspectKeys.<locals>.<lambda>_   s    6::r   )r   IsKnownAndSpecifiedupdater   GetValueadditionalPropertiesr    )r!   remove_aspects_arg_nameupdate_aspects_arg_namekeyss       r   _GenerateAspectKeysr1   B   s{    0 
$	566KK%MM12GG	
 
566KK567	r   c                T    U R                  U5      (       a  U R                  U5      $ S $ r   )r*   r,   )r!   r   s     r   _GetArgValueOrNoner3   j   s(     %)$<$<X$F$Fx	 PDPr   c                    U R                  S5      (       d  g[        R                  " U [        R                  R
                  SS9$ )z?Parse EntrySource labels from the command arguments if defined.entry_source_labelsN)
labels_clslabels_dest)r*   r   ParseCreateArgsdataplex_message GoogleCloudDataplexV1EntrySourceLabelsValuer!   s    r   _GetEntrySourceLabelsr=   p   sA    
 
	!	!"7	8	8		$	$
!BBNN'
 r   c                r    U R                  S5      (       d  / $ [        R                  " U R                  5      $ )zBParse EntrySource ancestors from the command arguments if defined.entry_source_ancestors)r*   dataplex_parsersParseEntrySourceAncestorsr?   r<   s    r   _GetEntrySourceAncestorsrB   ~   s2     
	!	!":	;	;I		3	3D4O4O	PPr   c                    [         R                  [        U S5      [        U S5      [        U S5      [        U S5      [        U S5      [        U 5      [	        U 5      [        U S5      [        U S5      S9	nU(       d  S	$ U$ )
z8Parse EntrySource from the command arguments if defined.entry_source_resourceentry_source_systementry_source_platformentry_source_display_nameentry_source_descriptionentry_source_create_timeentry_source_update_time)	resourcesystemplatformdisplayNamedescriptionlabels	ancestors
createTime
updateTimeN)r9   r:   r3   r=   rB   )r!   entry_sources     r   _GetEntrySourceOrNonerU      s     "BB!$(?@&;<!$(?@$T+FG$T+EF"4((.#D*DE#D*DE C 
, "3|3r   c                   U R                   R                  R                  5       nU R                   R                  R                  5       nU R                   R                  R                  5       n[
        R                  " 5       nSnUb  UR                  5       nUR                  R                  [        R                  UR                  5       [        R                  UR                  5       UR                  5       U[        U S5      [        U S5      [        U 5      S9UR!                  5       R                  5       S95      n["        R$                  " UR                  5       SR'                  UR!                  5       R                  5       5      S9  U$ )z9Create a CreateEntry request based on arguments provided. r   r   )name	entryTypeparentEntryfullyQualifiedNamer   entrySource)entryIdgoogleCloudDataplexV1Entryparentzin [{0}])details)CONCEPTSentryParse
entry_typeparent_entrydataplex_apiGetClientInstanceRelativeName&projects_locations_entryGroups_entriesCreater9   8DataplexProjectsLocationsEntryGroupsEntriesCreateRequestNameGoogleCloudDataplexV1Entryr3   rU   Parentr   CreatedResourceformat)r!   	entry_refentry_type_refparent_entry_refdataplex_clientparent_entry_namerK   s          r   rj   rj      sQ   mm!!''))==++113.]]//557 224/!(557CCJJOO.."%5%P%P))+&335+!3." )y9/5 &Q 	& !!#002 P (" nn	 0 0 2 ? ? AB 
/r   c                d   [        U 5      n[        U5      S:  a  [        R                  " S5      eU R                  R
                  R                  5       n[        R                  " 5       nUR                  R                  [        R                  UR                  5       [        R                  UR                  5       [        U S5      [        X5      [!        U 5      S9U R#                  U5      SR%                  U5      ['        U UUS9S95      n[(        R*                  " UR                  5       SS	9  U$ )
z:Create an UpdateEntry request based on arguments provided.   zIUpdate commands must specify at least one additional parameter to change.r   )rX   r[   r   r\   ,)r.   r/   )rX   r^   deleteMissingAspects
updateMask
aspectKeysrb   )kind)r$   lenr   HttpExceptionra   rb   rc   rf   rg   ri   Patchr9   7DataplexProjectsLocationsEntryGroupsEntriesPatchRequestrh   rm   r3   rU   r*   joinr1   r   UpdatedResource)r!   r.   r/   update_maskrq   rt   rK   s          r   Updater      s#    (-+

"
"	 
 mm!!'')) 224/CCIINN%%'%5%P%P))+!3." )G/5 &Q &  $77%  XXk*(&=&= O (. i,,.W=	/r   N)r!   parser_extensions.Namespacereturn	List[str])r!   r   r.   strr/   r   r   r   )r!   r   r   r   r   z
Any | None)r!   r   r   zDict[str, str] | None)r!   r   r   z	List[Any])r!   r   r   z8dataplex_message.GoogleCloudDataplexV1EntrySource | None)r!   r   )remove_aspectsupdate_aspects)r!   r   r.   r   r/   r   )__doc__
__future__r   typingr   r   r   googlecloudsdk.api_lib.dataplexr   rf   googlecloudsdk.callioper   r	   #googlecloudsdk.command_lib.dataplexr
   r@   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   GetMessageModuler9   r$   r1   r3   r=   rB   rU   rj   r   r   r   r   <module>r      s    = " " " @ . 5 K < #  002 D%
%% !% !	%
 %PQ
%Q14QQ
%Q
%QQ4
%4=4$!L $4#3)
%) ) !)r   