@ -25,6 +25,8 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace ;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder ;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem ;
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem ;
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItemType ;
import org.gcube.portlets.user.performfish.util.PFISHConstants ;
import org.gcube.portlets.user.performfish.util.Utils ;
import org.gcube.vomanagement.usermanagement.RoleManager ;
@ -35,7 +37,6 @@ import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject ;
import com.liferay.portal.kernel.log.LogFactoryUtil ;
import com.liferay.portal.kernel.servlet.ServletResponseUtil ;
import com.liferay.portal.kernel.upload.FileItem ;
import com.liferay.portal.kernel.upload.UploadPortletRequest ;
import com.liferay.portal.kernel.util.FileUtil ;
import com.liferay.portal.kernel.util.GetterUtil ;
@ -53,8 +54,6 @@ public class EmptyFormsDocumentsDisplay extends MVCPortlet {
public static final String FOLDERID_PREFERENCE_ATTR_NAME = "folderId" ;
private final static String RESOURCE_URL_ID = "uploadFiles" ;
private final static String UPLOADED_FILE_ATTR_NAME = "myfile" ;
private static String XLS_MIMETYPE = "application/vnd.ms-excel" ;
private static String XLSX_MIMETYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ;
public static final String ATTACHMENT_FOLDER = "_uploaded_forms" ;
private static RoleManager RM = new LiferayRoleManager ( ) ;
@Override
@ -86,9 +85,11 @@ public class EmptyFormsDocumentsDisplay extends MVCPortlet {
setGuestAuthorizationToken ( request ) ;
PortletPreferences portletPreferences = request . getPreferences ( ) ;
String folderId = GetterUtil . getString ( portletPreferences . getValue ( FOLDERID_PREFERENCE_ATTR_NAME , StringPool . BLANK ) ) ;
_log . info ( "\n\n *** folderId with empty forms:" + folderId ) ;
if ( folderId ! = null & & ! folderId . equals ( "" ) ) {
String context = Utils . getCurrentContext ( request ) ;
Workspace ws = Utils . getWS ( "guest" , context ) ;
String username = Utils . getCurrentUser ( request ) . getUsername ( ) ;
Workspace ws = Utils . getWS ( username , context ) ;
String selectedPhase = GetterUtil . getString ( portletPreferences . getValue ( PFISHConstants . PHASE_PREFERENCE_ATTR_NAME , StringPool . BLANK ) ) ;
//in theChildren expected to find 3 subfolders: Utils.SHOW_HATCHERY, SHOW_PRE_ONGROWING ..
@ -99,12 +100,12 @@ public class EmptyFormsDocumentsDisplay extends MVCPortlet {
List < FileItem > theInstructions = new ArrayList < > ( ) ;
List < String > theSheetNames = new ArrayList < > ( ) ;
//separate from instructions
for ( WorkspaceItem workspaceItem : thefiles ) {
for ( WorkspaceItem workspaceItem : thefiles ) {
if ( workspaceItem instanceof FileItem ) {
FileItem file = ( FileItem ) workspaceItem ;
if ( file . get ContentType( ) . equals ( XLS_MIMETYPE ) | | file . getContentType ( ) . equals ( XLSX_MIMETYPE ) ) { //is a form
if ( file . get FileItemType( ) = = FileItemType . DOCUMENT ) { //is a form
theSheets . add ( file ) ;
theSheetNames . add ( "'" + file . get File Name( ) + "'" ) ; //serializing for Javascript
theSheetNames . add ( "'" + file . get Name( ) + "'" ) ; //serializing for Javascript
}
else
theInstructions . add ( file ) ;
@ -137,7 +138,7 @@ public class EmptyFormsDocumentsDisplay extends MVCPortlet {
UploadPortletRequest uploadRequest = PortalUtil . getUploadPortletRequest ( resourceRequest ) ;
File multipartFile = uploadRequest . getFile ( UPLOADED_FILE_ATTR_NAME ) ;
FileItem[ ] items = uploadRequest . getMultipartParameterMap ( ) . get ( UPLOADED_FILE_ATTR_NAME ) ;
com. liferay . portal . kernel . upload . FileItem[ ] items = uploadRequest . getMultipartParameterMap ( ) . get ( UPLOADED_FILE_ATTR_NAME ) ;
String fileName = "" ;
String contentType = "" ;
for ( int i = 0 ; i < items . length ; i + + ) {
@ -180,7 +181,7 @@ public class EmptyFormsDocumentsDisplay extends MVCPortlet {
InputStream is = ws . downloadFile ( fileToDownloadId , theItem . getName ( ) , null , null ) . getStream ( ) ;
HttpServletResponse httpRes = PortalUtil . getHttpServletResponse ( resourceResponse ) ;
HttpServletRequest httpReq = PortalUtil . getHttpServletRequest ( resourceRequest ) ;
ServletResponseUtil . sendFile ( httpReq , httpRes , file . get File Name( ) , is , "application/download" ) ;
ServletResponseUtil . sendFile ( httpReq , httpRes , file . get Name( ) , is , "application/download" ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
@ -195,8 +196,9 @@ public class EmptyFormsDocumentsDisplay extends MVCPortlet {
* @return
* /
private void setGuestAuthorizationToken ( RenderRequest request ) {
String scope = Utils . getCurrentContext ( request ) ;
String authorizationToken = Utils . getCurrentUserToken ( scope , "guest" ) ;
String context = Utils . getCurrentContext ( request ) ;
String username = Utils . getCurrentUser ( request ) . getUsername ( ) ;
String authorizationToken = Utils . getCurrentUserToken ( context , username ) ;
SecurityTokenProvider . instance . set ( authorizationToken ) ;
}