Skip to content

Commit

Permalink
#24738 fix bug on pull
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrizzio-dotCMS committed Jun 22, 2023
1 parent 28c3a5a commit ccd6a2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.fileassets.business.FileAsset;
import com.dotmarketing.portlets.fileassets.business.FileAssetAPI;
import com.dotmarketing.portlets.folders.business.FolderAPI;
import com.dotmarketing.portlets.folders.model.Folder;
import com.dotmarketing.portlets.languagesmanager.business.LanguageAPI;
import com.dotmarketing.portlets.languagesmanager.model.Language;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class WebAssetHelper {

ContentTypeAPI contentTypeAPI;

FolderAPI folderAPI;

/**
* Constructor for testing
Expand All @@ -74,14 +76,16 @@ public class WebAssetHelper {
final ContentletAPI contentletAPI,
final BrowserAPI browserAPI,
final TempFileAPI tempFileAPI,
final ContentTypeAPI contentTypeAPI
final ContentTypeAPI contentTypeAPI,
final FolderAPI folderAPI
){
this.languageAPI = languageAPI;
this.fileAssetAPI = fileAssetAPI;
this.contentletAPI = contentletAPI;
this.browserAPI = browserAPI;
this.tempFileAPI = tempFileAPI;
this.contentTypeAPI = contentTypeAPI;
this.folderAPI = folderAPI;
}

/**
Expand All @@ -94,7 +98,8 @@ public class WebAssetHelper {
APILocator.getContentletAPI(),
APILocator.getBrowserAPI(),
APILocator.getTempFileAPI(),
APILocator.getContentTypeAPI(APILocator.systemUser())
APILocator.getContentTypeAPI(APILocator.systemUser()),
APILocator.getFolderAPI()
);
}

Expand Down Expand Up @@ -333,6 +338,7 @@ public File getAssetContent(final AssetsRequestForm form, final User user)
return fileAsset.getFileAsset();
}


public WebAssetView saveUpdateAsset(final HttpServletRequest request, final FileUploadData form,
final User user) throws DotDataException, DotSecurityException, IOException {

Expand Down Expand Up @@ -381,7 +387,7 @@ public WebAssetView saveUpdateAsset(final HttpServletRequest request, final File
builder.withHostOrFolderId(folder.getInode());
}

builder.withFilter(assetName);
builder.withFileName(assetName);
final List<Treeable> folderContent = browserAPI.getFolderContentList(builder.build());
final List<Contentlet> assets = folderContent.stream()
.filter(Contentlet.class::isInstance).map(Contentlet.class::cast)
Expand Down Expand Up @@ -474,11 +480,11 @@ Optional<Language> lang(final String language, final boolean defaultLangFallback
Language resolvedLang = Try.of(() -> {
//Typically locales are separated by a dash, but our Language API uses an underscore in the toString method
//So here I'm preparing for both cases
final String splitBy = language.contains("-") ? "-" : language.contains("_") ? "_" : null;
if (null == splitBy) {
final Optional<String> splitBy = splitBy(language);
if (splitBy.isEmpty()) {
return languageAPI.getLanguage(language,null);
}
final String[] split = language.split(splitBy, 2);
final String[] split = language.split(splitBy.get(), 2);
return languageAPI.getLanguage(split[0], split[1]);
}
).getOrNull();
Expand All @@ -491,6 +497,21 @@ Optional<Language> lang(final String language, final boolean defaultLangFallback
return Optional.ofNullable(resolvedLang);
}

/**
* Splits the language by either a dash or underscore
* @param language
* @return
*/
Optional<String> splitBy(final String language){
if(language.contains("-")){
return Optional.of("-");
}
if(language.contains("_")){
return Optional.of("_");
}
return Optional.empty();
}

/**
* Creates a new instance of {@link WebAssetHelper}
* @return {@link WebAssetHelper}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
Expand Down

0 comments on commit ccd6a2b

Please sign in to comment.