dotCMS / dotCMS/core

setDefaultValues throws errors with new fileassets

Open
#32,936 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Changelog: Skip stale Team : Scout Type : Defect
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Problem Statement

This occurs when you try to use contentAPI.checkin(FileAsset....) rather than contentAPI.checkin(Contentlet....).

When checking in a fileAsset, we call the new setDefaultValues(final Contentlet contentlet)
to set all the default values. This calls a contentlet.getMap() which, if the contentlet is a fileAsset, calls the FileAsset.getMap() method which calls fileAsset.isLocked() which expects the content to have been persisted. This means we get a NPE error checking in fileassets now. This does not stop the checkin flow (not sure why not) but it does make it look like your content repository is messed up somehow. I spent awhile debugging another issue thinking this was the cause.

11:15:49.686  ERROR business.FileAsset - Failed to retrieve live/working/deleted/locked status for FileAsset 'searchProductsBefore.gql' [ 21538549-31c3-4cfe-b38a-965fcb2b7d03 ]: No version info. Call setWorking first c2a373b99e91f7cbb89cfc4028345653
com.dotmarketing.business.DotStateException: No version info. Call setWorking first c2a373b99e91f7cbb89cfc4028345653
	at com.dotmarketing.business.VersionableAPIImpl.getContentletVersionInfo(VersionableAPIImpl.java:327) ~[?:?]
	at com.dotmarketing.business.VersionableAPIImpl.isLocked(VersionableAPIImpl.java:345) ~[?:?]
	at com.dotmarketing.portlets.contentlet.model.Contentlet.isLocked(Contentlet.java:914) ~[?:?]
	at com.dotmarketing.portlets.fileassets.business.FileAsset.isLocked(FileAsset.java:297) ~[?:?]
	at com.dotmarketing.portlets.fileassets.business.FileAsset.getMap(FileAsset.java:324) ~[?:?]
	at com.dotcms.content.elasticsearch.business.ESContentFactoryImpl.setUpContentletAsJson(ESContentFactoryImpl.java:2347) ~[?:?]
	at com.dotcms.content.elasticsearch.business.ESContentFactoryImpl.save(ESContentFactoryImpl.java:2324) ~[?:?]
	at com.dotcms.content.elasticsearch.business.ESContentFactoryImpl.save(ESContentFactoryImpl.java:2316) ~[?:?]
Steps to Reproduce

Checkin Code:

        FileAsset fileAsset = new FileAsset();
        fileAsset.setFolder(destFolder.getIdentifier());
        fileAsset.setHost(site.getIdentifier());
        fileAsset.setStringProperty(FileAssetAPI.FILE_NAME_FIELD, fileName);
        fileAsset.setBinary(FileAssetAPI.BINARY_FIELD, tmpFile);
        fileAsset.setTitle(fileName);
        fileAsset.setContentTypeId(APILocator.getContentTypeAPI(APILocator.systemUser())
            .find(FileAssetAPI.DEFAULT_FILE_ASSET_STRUCTURE_VELOCITY_VAR_NAME).id());
        fileAsset.setProperty(Contentlet.DISABLE_WORKFLOW, true);
        fileAsset.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());
        Contentlet dotfile = APILocator.getContentletAPI().checkin(fileAsset, APILocator.systemUser(), false);

Acceptance Criteria

This code should not throw an error in the logs.

dotCMS Version

latest

Proposed Objective

Technical User Experience

Proposed Priority

Priority 3 - Average

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

No response

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ESContentFactoryImpl.setUpContentletAsJson and save, then follow the FileAsset.getMap and isLocked calls shown in the stack trace. Reproduce with the provided contentAPI.checkin(FileAsset) example and verify that checking in a new file asset completes without an error in the logs.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.