
    !                       d Z ddlmZ ddlmZmZmZ ddlmZ	 ddl
mZ ddl
mZ ddlmZ ddlmZ dd	lmZ  e	j(                         Zdd
Z	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 ddZddZ	 	 d	 	 	 	 	 ddZy)z6Client for interaction with Entries API CRUD DATAPLEX.    )annotations)AnyDictList)util)
exceptions)parser_extensions)parsers)labels_util)logc                    dddddddddddd	d
dt        t        d | j                                     }|j                        }t	        t        t        fd|                  S )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                &    | j                  dd      S )Nz--clear-z--)replace)args    ,lib/googlecloudsdk/api_lib/dataplex/entry.py<lambda>z)_GetFieldsForUpdateMask.<locals>.<lambda>9   s    ckk*d3    c                    |    S N )arg_namearg_name_to_fields    r   r   z)_GetFieldsForUpdateMask.<locals>.<lambda>>   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                  t               }| j                  |      r5|j                  t        d | j	                  |      j
                               | j                  |      r |j                  | j	                  |             t        |      S )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                    | j                   S r   )key)aspects    r   r   z%_GenerateAspectKeys.<locals>.<lambda>_   s    6::r   )r   IsKnownAndSpecifiedupdater   GetValueadditionalPropertiesr   )r    remove_aspects_arg_nameupdate_aspects_arg_namekeyss       r   _GenerateAspectKeysr/   B   su    0 
$	56KK%MM12GG	
 
56KK567	r   c                J    | j                  |      r| j                  |      S d S r   )r(   r*   )r    r   s     r   _GetArgValueOrNoner1   j   s%     %)$<$<X$Fx	 PDPr   c                    | j                  d      syt        j                  | t        j                  j
                  d      S )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   s>    
 
	!	!"7	8		$	$
!BBNN'
 r   c                f    | j                  d      sg S t        j                  | j                        S )zBParse EntrySource ancestors from the command arguments if defined.entry_source_ancestors)r(   dataplex_parsersParseEntrySourceAncestorsr=   r:   s    r   _GetEntrySourceAncestorsr@   ~   s/     
	!	!":	;I		3	3D4O4O	PPr   c                    t         j                  t        | d      t        | d      t        | d      t        | d      t        | d      t        |       t	        |       t        | d      t        | d      	      }|sd	S |S )
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)r7   r8   r1   r;   r@   )r    entry_sources     r   _GetEntrySourceOrNonerS      s     "BB!$(?@&;<!$(?@$T+FG$T+EF"4((.#D*DE#D*DE C 
, "3|3r   c                (   | j                   j                  j                         }| j                   j                  j                         }| j                   j                  j                         }t        j                         }d}||j                         }|j                  j                  t        j                  |j                         t        j                  |j                         |j                         |t        | d      t        | d      t        |             |j!                         j                                     }t#        j$                  |j                         dj'                  |j!                         j                                      |S )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Creater7   8DataplexProjectsLocationsEntryGroupsEntriesCreateRequestNameGoogleCloudDataplexV1Entryr1   rS   Parentr   CreatedResourceformat)r    	entry_refentry_type_refparent_entry_refdataplex_clientparent_entry_namerI   s          r   rh   rh      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                v   t        |       }t        |      dk  rt        j                  d      | j                  j
                  j                         }t        j                         }|j                  j                  t        j                  |j                         t        j                  |j                         t        | d      t        | |      t!        |             | j#                  |      dj%                  |      t'        | ||                  }t)        j*                  |j                         d	       |S )
z:Create an UpdateEntry request based on arguments provided.   zIUpdate commands must specify at least one additional parameter to change.r   )rV   rY   r   rZ   ,)r,   r-   )rV   r\   deleteMissingAspects
updateMask
aspectKeysr`   )kind)r#   lenr   HttpExceptionr_   r`   ra   rd   re   rg   Patchr7   7DataplexProjectsLocationsEntryGroupsEntriesPatchRequestrf   rk   r1   rS   r(   joinr/   r   UpdatedResource)r    r,   r-   update_maskro   rr   rI   s          r   Updater      s&    (-+

"
"	 
 mm!!'')) 224/CCIINN%%'%5%P%P))+!3." )/F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   rd   googlecloudsdk.callioper   r	   #googlecloudsdk.command_lib.dataplexr
   r>   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   GetMessageModuler7   r#   r/   r1   r;   r@   rS   rh   r   r   r   r   <module>r      s    = " " " @ . 5 K < # 1<002 D%
%% !% !	%
 %PQ
%Q14QQ
%Q
%QQ4
%4=4$!L $4#3)
%) ) !)r   