@@ -107,50 +107,82 @@ export class IdentifierComponent extends RenderingTypeValueModelComponent implem
107107 return identifier ;
108108 }
109109
110+ /**
111+ * Create a MetadataLinkValue object with the given href and text
112+ * @param href the href value
113+ * @param text the text value
114+ * @returns MetadataLinkValue object
115+ */
116+ private createMetadataLinkValue ( href : string , text : string ) : MetadataLinkValue {
117+ text = text . trim ( ) !== '' ? text : href ;
118+ return { href, text } ;
119+ }
120+
110121 /**
111122 * Set href and text of the component based on urn
112- * and the given metadata value
123+ * and the given metadata value.
124+ * Is handling the case when the urn is configured in the default-app-config
125+ * and the link is pre-configured.
113126 * @param metadataValue the metadata value
114127 * @param urn URN type (doi, hdl, mailto)
115128 */
116129 composeLink ( metadataValue : string , urn : string ) : MetadataLinkValue {
130+ const subtypeValue = this . getIdentifierSubtypeValue ( ) ;
131+
132+ if ( hasValue ( subtypeValue ) ) {
133+ const href = this . validateLink ( metadataValue ) ? metadataValue : `${ subtypeValue . link } /${ metadataValue } ` ;
134+ return this . createMetadataLinkValue ( href , metadataValue ) ;
135+ }
136+
117137 let value = metadataValue ;
118- const rep = urn + ':' ;
138+ const rep = ` ${ urn } :` ;
119139 if ( metadataValue . startsWith ( rep ) ) {
120140 value = metadataValue . replace ( rep , '' ) ;
121141 }
122142 const href = this . resolver . getBaseUrl ( urn ) + value ;
123- const text = isNotEmpty ( value ) && value !== '' ? value : href ;
124- return {
125- href,
126- text
127- } ;
143+ return this . createMetadataLinkValue ( href , value ) ;
128144 }
129145
130146 ngOnInit ( ) : void {
131147 this . identifier = this . getIdentifierFromValue ( ) ;
132- this . getSubtypeValue ( ) ;
148+ this . setIconDetails ( ) ;
133149 }
134150
135151 /**
136- * Retrieves the subtype value for the identifier component .
152+ * Sets the icon details based on the identifier subtype configuration .
137153 * If the identifier subtype is not empty, it searches for the subtype with a matching name to the rendering subtype.
138154 * If a matching subtype is found, it sets the icon position, subtype icon, and icon link based on the subtype's properties.
139155 */
140- private getSubtypeValue ( ) {
156+ private setIconDetails ( ) {
157+ const subtypeVal = this . getIdentifierSubtypeValue ( ) ;
158+ if ( hasNoValue ( subtypeVal ) ) {
159+ return ;
160+ }
161+ this . iconPosition = subtypeVal . iconPosition ;
162+ this . subTypeIcon = subtypeVal . iconPosition !== IdentifierSubtypesIconPositionEnum . NONE ? subtypeVal ?. icon : '' ;
163+ this . iconLink = subtypeVal ?. link ;
164+ }
165+
166+ /**
167+ * Retrieves the value of the identifier subtype configuration based on the rendering subtype.
168+ * @returns The identifier subtype configuration object.
169+ */
170+ private getIdentifierSubtypeValue ( ) : IdentifierSubtypesConfig {
141171 if ( isNotEmpty ( this . identifierSubtypeConfig ) ) {
142172 const subtypeVal = this . identifierSubtypeConfig . find ( ( subtype ) => subtype . name === this . renderingSubType ) ;
143- if ( hasNoValue ( subtypeVal ) ) {
144- return ;
145- }
146-
147- this . iconPosition = subtypeVal . iconPosition ;
148- this . subTypeIcon = subtypeVal . iconPosition !== IdentifierSubtypesIconPositionEnum . NONE ? subtypeVal ?. icon : '' ;
149- this . iconLink = subtypeVal ?. link ;
173+ return subtypeVal ;
150174 }
151175 }
152176
153- // TODO: Check the internal | external link
154- // TODO: UNIT TESTs
155-
177+ /**
178+ * Check if the given link is valid
179+ * @param link the link to check
180+ * @returns true if the link is valid, false otherwise
181+ */
182+ private validateLink ( link : string ) : boolean {
183+ const urlRegex = / ^ ( h t t p | h t t p s ) : \/ \/ [ ^ " ] + $ / ;
184+ return urlRegex . test ( link ) ;
185+ }
156186}
187+
188+
0 commit comments