Class ApplicationCenterService

java.lang.Object
io.meeds.appcenter.service.ApplicationCenterService

@Service public class ApplicationCenterService extends Object
A Service to access and store applications
  • Field Details

    • ANY_PERMISSION

      public static final String ANY_PERMISSION
      See Also:
    • DEFAULT_USERS_GROUP

      public static final String DEFAULT_USERS_GROUP
      See Also:
    • DEFAULT_USERS_PERMISSION

      public static final String DEFAULT_USERS_PERMISSION
      See Also:
    • MAX_FAVORITE_APPS

      public static final String MAX_FAVORITE_APPS
      See Also:
    • APP_CENTER_SETTINGS_KEY

      public static final String APP_CENTER_SETTINGS_KEY
      SettingService key under which the whole app-center configuration is stored, serialized as a single JSON blob (see ApplicationCenterSettings). Storing all settings under one key lets new settings be added as POJO fields without introducing a new setting key nor an upgrade plugin.
      See Also:
    • DEFAULT_APP_IMAGE_NAME

      public static final String DEFAULT_APP_IMAGE_NAME
      See Also:
    • DEFAULT_APP_IMAGE_BODY

      public static final String DEFAULT_APP_IMAGE_BODY
      See Also:
    • DEFAULT_LIMIT

      public static final int DEFAULT_LIMIT
      See Also:
    • APP_CENTER_CONTEXT

      public static final org.exoplatform.commons.api.settings.data.Context APP_CENTER_CONTEXT
    • APP_CENTER_SCOPE

      public static final org.exoplatform.commons.api.settings.data.Scope APP_CENTER_SCOPE
  • Constructor Details

    • ApplicationCenterService

      public ApplicationCenterService()
  • Method Details

    • createApplication

      public Application createApplication(Application application, String username) throws IllegalAccessException
      Create new Application that will be available for all users.
      Parameters:
      application - application to create
      username - user making the operation
      Returns:
      stored Application in datasource
      Throws:
      IllegalAccessException - if user is not allowed to create an application
    • createApplication

      public Application createApplication(Application application)
      Create new Application that will be available for all users.
      Parameters:
      application - application to create
      Returns:
      stored Application in datasource
    • getApplication

      public Application getApplication(long applicationId)
      Get an application by id
      Parameters:
      applicationId - application to find
      Returns:
      stored Application in datasource
    • findSystemApplicationByUrl

      public Application findSystemApplicationByUrl(String url)
    • updateApplication

      public void updateApplication(Application application, String username) throws IllegalAccessException, ApplicationNotFoundException
      Update an existing application on datasource. If the application doesn't exit an ApplicationNotFoundException will be thrown.
      Parameters:
      application - dto to update on store
      username - username storing application
      Throws:
      IllegalAccessException - if user is not allowed to update application
      ApplicationNotFoundException - if application wasn't found
    • updateApplication

      public void updateApplication(Application application)
    • deleteApplication

      public void deleteApplication(Long applicationId, String username) throws ApplicationNotFoundException, IllegalAccessException
      Delete application identified by its id and check if username has permission to delete it.
      Parameters:
      applicationId - technical identifier of application
      username - user currently deleting application
      Throws:
      IllegalAccessException - if user is not allowed to delete application
      ApplicationNotFoundException - if application wasn't found
    • deleteApplication

      public void deleteApplication(Long applicationId) throws ApplicationNotFoundException
      Throws:
      ApplicationNotFoundException
    • addFavoriteApplication

      public void addFavoriteApplication(long applicationId, String username) throws ApplicationNotFoundException, IllegalAccessException
      Add an application, identified by its technical id, as favorite of a user
      Parameters:
      applicationId - technical application id
      username - user login
      Throws:
      ApplicationNotFoundException - when application is not found
      IllegalAccessException - if user hasn't access permission to the application
    • deleteFavoriteApplication

      public void deleteFavoriteApplication(Long applicationId, String username)
      Deletes an application identified by its id from favorite applications of user
      Parameters:
      applicationId - application technical identifier
      username - login of user currently deleting application
    • getSettings

      public ApplicationCenterSettings getSettings()
      Returns the global app-center settings, deserialized from the single JSON blob stored in SettingService. When no blob is stored yet, sane defaults are returned (see getStoredSettings()).
      Returns:
      the current ApplicationCenterSettings, never null
    • saveSettings

      public void saveSettings(ApplicationCenterSettings settings, String username) throws IllegalAccessException
      Persists the whole app-center settings blob. The incoming settings are merged onto the currently stored ones (so a partial update never drops fields it didn't set) then serialized back as a single JSON blob. Admin only.
      Parameters:
      settings - the settings to persist, must not be null
      username - the user performing the operation
      Throws:
      IllegalAccessException - if the user is not allowed to change app-center settings
    • isUserPersonalAppsEnabled

      public boolean isUserPersonalAppsEnabled()
      Returns whether users are allowed to create personal URL apps.
      Returns:
      true if the personal URL apps feature is enabled
    • setUserPersonalAppsEnabled

      public void setUserPersonalAppsEnabled(boolean enabled, String username) throws IllegalAccessException
      Enables or disables the user personal apps feature. Admin only. The value is merged into the settings JSON blob (see saveSettings(io.meeds.appcenter.model.ApplicationCenterSettings, java.lang.String)).
      Parameters:
      enabled - whether the personal apps feature should be enabled
      username - the user performing the operation
      Throws:
      IllegalAccessException - if the user is not allowed to change app-center settings
    • createPersonalApplication

      public Application createPersonalApplication(Application application, String username) throws IllegalAccessException
      Creates a personal URL application for the given user.
      Throws:
      IllegalAccessException
    • updatePersonalApplication

      public void updatePersonalApplication(Application application, String username) throws IllegalAccessException, ApplicationNotFoundException
      Updates a personal URL application. Only the owner may update it.
      Throws:
      IllegalAccessException
      ApplicationNotFoundException
    • normalizePersonalUrl

      protected String normalizePersonalUrl(String url)
      Normalizes an URL entered by an end user for a personal application. The scheme is optional, so that "meeds.io" is stored as "https://meeds.io"; when it is omitted the host must be qualified, so that a plain word is rejected instead of silently becoming a link to a non existing host. Only http and https are accepted, which rules out "javascript:" links. Portal relative links ("/portal/dw", "./dw") are kept as is, but scheme relative ones ("//host", which a browser resolves to an external origin) are rejected. This method is the security boundary: the mirror written in ApplicationUrlService.js only exists to give an immediate feedback in the form, and both must be updated together.
      Parameters:
      url - the URL as entered by the user
      Returns:
      the normalized URL, either an absolute http(s) link or a portal relative one
      Throws:
      IllegalArgumentException - if the URL is blank or isn't an http(s) link
    • deletePersonalApplication

      public void deletePersonalApplication(Long applicationId, String username) throws IllegalAccessException, ApplicationNotFoundException
      Deletes a personal URL application. Only the owner may delete it.
      Throws:
      IllegalAccessException
      ApplicationNotFoundException
    • getApplications

      public ApplicationList getApplications(int offset, int limit, String keyword)
      Retrieves the list of applications with offset, limit and a keyword that can be empty
      Parameters:
      offset - offset of the query
      limit - limit of the query that can be less or equal to 0, which mean, getting all available applications
      keyword - used to search in title and url
      Returns:
      ApplicationList that contains the list of applications
    • getApplications

      public ApplicationList getApplications(int offset, int limit, String keyword, Locale locale)
      Retrieves the list of applications with offset, limit and a keyword that can be empty
      Parameters:
      offset - offset of the query
      limit - limit of the query that can be less or equal to 0, which mean, getting all available applications
      keyword - used to search in title and url
      locale - used language to retrieve application title and description
      Returns:
      ApplicationList that contains the list of applications
    • getActiveApplications

      public ApplicationList getActiveApplications(int offset, int limit, String keyword, String username)
      Retrieves the list of applications switch offset and limit of the query, a keyword to filter on title and url of Application and the username to filter on authorized applications
      Parameters:
      offset - offset of the query
      limit - limit of the query that can be less or equal to 0, which mean, getting all available applications
      keyword - used to search in title and url
      username - login of user to use to filter on authorized applications
      Returns:
      ApplicationList that contains the List of authorized UserApplication
    • getActiveApplications

      public ApplicationList getActiveApplications(int offset, int limit, String keyword, Locale locale, String username)
      Retrieves the list of applications switch offset and limit of the query, a keyword to filter on title and url of Application and the username to filter on authorized applications
      Parameters:
      offset - offset of the query
      limit - limit of the query that can be less or equal to 0, which mean, getting all available applications
      keyword - used to search in title and url
      username - login of user to use to filter on authorized applications
      Returns:
      ApplicationList that contains the List of authorized UserApplication
    • updateFavoriteApplicationOrder

      public void updateFavoriteApplicationOrder(ApplicationOrder applicationOrder, String userName) throws ApplicationNotFoundException
      Update favorite applications order for a user
      Parameters:
      applicationOrder -
      userName -
      Throws:
      ApplicationNotFoundException
    • getApplicationImageLastUpdated

      public Long getApplicationImageLastUpdated(long applicationId) throws ApplicationNotFoundException
      Return the Application illustration last modifed timestamp (in ms), if not found, the default image last modifed timestamp will be retrieved
      Parameters:
      applicationId - technical id of application
      Returns:
      timestamp in milliseconds of last modified date of illustration
      Throws:
      ApplicationNotFoundException - if application wasn't found
    • getApplicationImageInputStream

      public InputStream getApplicationImageInputStream(long applicationId) throws ApplicationNotFoundException
      Return the Application illustration InputStream, if not found, the default image InputStream will be retrieved
      Parameters:
      applicationId - technical id of application
      Returns:
      InputStream of application illustration
      Throws:
      ApplicationNotFoundException - if application wasn't found
    • getApplicationImageInputStream

      public InputStream getApplicationImageInputStream(long applicationId, String dimensions) throws ApplicationNotFoundException
      Return the Application illustration InputStream, if not found, the default image InputStream will be retrieved
      Parameters:
      applicationId - technical id of application
      dimensions - Image dimensions to retrieve
      Returns:
      InputStream of application illustration
      Throws:
      ApplicationNotFoundException - if application wasn't found
    • getSystemApplications

      public List<Application> getSystemApplications()
    • getCategoryIds

      public List<Long> getCategoryIds()
    • getMandatoryAndFavoriteApplications

      public ApplicationList getMandatoryAndFavoriteApplications(org.springframework.data.domain.Pageable pageable, String username, Locale locale)
    • getApplicationShortcuts

      public List<String> getApplicationShortcuts(String username)
    • canAccess

      public boolean canAccess(Application application, String username)
    • canEdit

      public boolean canEdit(String username)