11package com .dotmarketing .util ;
22
3+ import static com .dotmarketing .portlets .contentlet .model .Contentlet .IDENTIFIER_KEY ;
4+ import static com .dotmarketing .portlets .contentlet .model .Contentlet .STRUCTURE_INODE_KEY ;
35import static com .dotmarketing .util .importer .HeaderValidationCodes .HEADERS_NOT_FOUND ;
46import static com .dotmarketing .util .importer .ImportLineValidationCodes .LANGUAGE_NOT_FOUND ;
57
68import com .dotcms .content .elasticsearch .util .ESUtils ;
9+ import com .dotcms .contenttype .business .ContentTypeAPI ;
710import com .dotcms .contenttype .model .field .BinaryField ;
811import com .dotcms .contenttype .model .field .HostFolderField ;
912import com .dotcms .contenttype .model .type .BaseContentType ;
1821import com .dotmarketing .beans .Identifier ;
1922import com .dotmarketing .beans .Permission ;
2023import com .dotmarketing .business .APILocator ;
21- import com .dotmarketing .business .CacheLocator ;
2224import com .dotmarketing .business .DotValidationException ;
2325import com .dotmarketing .business .PermissionAPI ;
2426import com .dotmarketing .cache .FieldsCache ;
8385import com .liferay .portal .model .User ;
8486import com .liferay .util .StringPool ;
8587import io .vavr .Lazy ;
88+ import io .vavr .control .Try ;
8689import java .io .File ;
8790import java .io .IOException ;
8891import java .io .Reader ;
110113import org .apache .commons .lang3 .StringUtils ;
111114import org .apache .commons .lang3 .tuple .ImmutablePair ;
112115import org .apache .commons .lang3 .tuple .Pair ;
113- import org .apache .juli .logging .Log ;
114116
115117/**
116118 * Provides utility methods to import content into dotCMS. The data source is a
@@ -134,6 +136,7 @@ public class ImportUtil {
134136 private final static HostAPI hostAPI = APILocator .getHostAPI ();
135137 private final static FolderAPI folderAPI = APILocator .getFolderAPI ();
136138 private final static WorkflowAPI workflowAPI = APILocator .getWorkflowAPI ();
139+ private final static ContentTypeAPI contentTypeAPI = APILocator .getContentTypeAPI (APILocator .systemUser ());
137140
138141 public static final String KEY_WARNINGS = "warnings" ;
139142 public static final String KEY_ERRORS = "errors" ;
@@ -294,8 +297,12 @@ public static HashMap<String, List<String>> importFile(
294297 public static ImportResult importFileResult (final ImportFileParams params )
295298 throws DotRuntimeException , DotDataException {
296299
297- Structure contentType = CacheLocator .getContentTypeCache ()
298- .getStructureByInode (params .contentTypeInode ());
300+ final ContentType type = Try .of (()->contentTypeAPI .find (params .contentTypeInode ())).getOrNull ();
301+ if (type == null ) {
302+ throw new DotDataValidationException ("Content type not found for inode: " + params .contentTypeInode ());
303+ }
304+ Structure contentType = new StructureTransformer (type ).asStructure ();
305+
299306 List <Permission > contentTypePermissions = permissionAPI .getPermissions (contentType );
300307 List <UniqueFieldBean > uniqueFieldBeans = new ArrayList <>();
301308
@@ -1666,10 +1673,8 @@ private static void importLine(
16661673 fieldResults .categories ().forEach (resultBuilder ::addCategory );
16671674 uniqueFieldBeans .addAll (fieldResults .uniqueFields ());
16681675
1669- final Map <Integer , Object > values = new HashMap <>();
1670- final Set <Category > categories = new HashSet <>();
1671- values .putAll (fieldResults .values ());
1672- categories .addAll (fieldResults .categories ());
1676+ final Map <Integer , Object > values = new HashMap <>(fieldResults .values ());
1677+ final Set <Category > categories = new HashSet <>(fieldResults .categories ());
16731678
16741679 if (fieldResults .ignoreLine ()) {
16751680 resultBuilder .setIgnoreLine (true );
@@ -1808,7 +1813,7 @@ private static void importLine(
18081813 }
18091814 }
18101815
1811- ProcessedContentResult processResult = processContent (
1816+ final ProcessedContentResult processResult = processContent (
18121817 lineNumber ,
18131818 contentlets ,
18141819 resultBuilder .isNewContent (),
@@ -2572,7 +2577,7 @@ private static ContentletSearchResult searchExistingContentlets(
25722577
25732578 if (UtilMethods .isSet (identifier )) {
25742579 contentlets .addAll (
2575- searchByIdentifier (identifier , contentType , user ));
2580+ searchByIdentifierFromDB (identifier , contentType , user ));
25762581 } else if (urlValue != null && keyFields .isEmpty ()) {
25772582 // For HTMLPageAsset, we need to search by URL to math existing pages
25782583 contentlets .addAll (searchByUrl (contentType , urlValue , siteAndFolder , language , user ));
@@ -2608,29 +2613,27 @@ private static ContentletSearchResult searchExistingContentlets(
26082613 * @throws DotSecurityException If the user does not have permission to access the requested
26092614 * contentlet.
26102615 */
2611- private static List <Contentlet > searchByIdentifier (
2616+ private static List <Contentlet > searchByIdentifierFromDB (
26122617 final String identifier ,
26132618 final Structure contentType ,
26142619 final User user
26152620 ) throws DotDataException , DotSecurityException {
26162621
2617- StringBuilder query = new StringBuilder ()
2618- . append ( "+structureName:" ). append ( contentType . getVelocityVarName ())
2619- . append ( " +working:true +deleted:false" )
2620- . append ( " +identifier:" ). append ( identifier );
2622+ final Contentlet contentlet = new Contentlet ( Map . of (
2623+ IDENTIFIER_KEY , identifier ,
2624+ STRUCTURE_INODE_KEY , contentType . getInode ( )
2625+ ) );
26212626
2622- List <ContentletSearch > contentsSearch = conAPI .searchIndex (query .toString (), 0 , -1 , null ,
2623- user , true );
2624-
2625- if (contentsSearch == null || contentsSearch .isEmpty ()) {
2627+ final List <Contentlet > allLanguages = conAPI .getAllLanguages (contentlet , false , user , true );
2628+ if (allLanguages == null || allLanguages .isEmpty ()) {
26262629 throw ImportLineException .builder ()
26272630 .message ("Content not found with identifier" )
26282631 .code (ImportLineValidationCodes .CONTENT_NOT_FOUND .name ())
26292632 .invalidValue (identifier )
26302633 .build ();
26312634 }
26322635
2633- return convertSearchResults ( contentsSearch , user );
2636+ return allLanguages . stream (). map ( Contentlet :: new ). collect ( Collectors . toList () );
26342637 }
26352638
26362639 /**
@@ -3051,7 +3054,7 @@ private static ProcessedContentResult processContent(
30513054 final String [] line
30523055 ) throws DotDataException , DotSecurityException , IOException , LanguageException {
30533056
3054- ProcessedContentResultBuilder resultBuilder = new ProcessedContentResultBuilder ();
3057+ final ProcessedContentResultBuilder resultBuilder = new ProcessedContentResultBuilder ();
30553058
30563059 for (Contentlet cont : contentlets ) {
30573060
@@ -3333,14 +3336,11 @@ private static void saveContent(
33333336
33343337 cont .setLowIndexPriority (true );
33353338
3336- final var validationResult = validateWorkflowExecution (lineNumber , wfActionId , cont , user ,
3337- resultBuilder );
3338- if (validationResult .getLeft ()) {
3339- executeWorkflowAction (cont , categories , validationResult .getRight (), relationships ,
3340- user );
3339+ final var validationResult = validateWorkflowExecution (lineNumber , wfActionId , cont , user , resultBuilder );
3340+ if (Boolean .TRUE .equals (validationResult .getLeft ())) {
3341+ cont = executeWorkflowAction (cont , categories , validationResult .getRight (), relationships , user );
33413342 } else {
3342- cont = runWorkflowIfCould (user , contentTypePermissions , categories , cont ,
3343- relationships );
3343+ cont = runWorkflowIfCould (user , contentTypePermissions , categories , cont , relationships );
33443344 }
33453345
33463346 processTagFields (cont , headers , values , siteAndFolder );
@@ -3623,7 +3623,7 @@ private static Pair<Boolean, WorkflowAction> validateWorkflowExecution(
36233623 * @throws DotDataException If an error occurs during workflow execution or processing.
36243624 * @throws DotSecurityException If a security-related exception occurs during execution.
36253625 */
3626- private static void executeWorkflowAction (
3626+ private static Contentlet executeWorkflowAction (
36273627 final Contentlet cont ,
36283628 final List <Category > categories ,
36293629 final WorkflowAction executeWfAction ,
@@ -3635,17 +3635,17 @@ private static void executeWorkflowAction(
36353635 cont .setBoolProperty (Contentlet .SKIP_RELATIONSHIPS_VALIDATION ,
36363636 relationships == null || relationships .getRelationshipsRecords ().isEmpty ());
36373637
3638- workflowAPI .fireContentWorkflow (cont ,
3639- new ContentletDependencies .Builder ()
3640- .respectAnonymousPermissions (Boolean .FALSE )
3641- .modUser (user )
3642- .relationships (relationships )
3643- .workflowActionId (executeWfAction .getId ())
3644- .workflowActionComments ("" )
3645- .workflowAssignKey ("" )
3646- .categories (categories )
3647- .generateSystemEvent (Boolean .FALSE )
3648- .build ());
3638+ return workflowAPI .fireContentWorkflow (cont ,
3639+ new ContentletDependencies .Builder ()
3640+ .respectAnonymousPermissions (Boolean .FALSE )
3641+ .modUser (user )
3642+ .relationships (relationships )
3643+ .workflowActionId (executeWfAction .getId ())
3644+ .workflowActionComments ("" )
3645+ .workflowAssignKey ("" )
3646+ .categories (categories )
3647+ .generateSystemEvent (Boolean .FALSE )
3648+ .build ());
36493649 }
36503650
36513651 /**
0 commit comments