Example usage for com.liferay.portal.kernel.util PropsUtil get

List of usage examples for com.liferay.portal.kernel.util PropsUtil get

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PropsUtil get.

Prototype

public static String get(String key) 

Source Link

Usage

From source file:com.liferay.lms.service.impl.CompetenceLocalServiceImpl.java

License:Open Source License

public String getBGImageURL(long groupId, HttpServletRequest request) {

    String imageurl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/default-cert.jpg";
    String baseDir = PropsUtil.get("liferay.home") + "/data/compimages";
    File baseDirFile = new File(baseDir);
    if (baseDirFile.exists()) {
        File imageFile = new File(baseDirFile.getAbsolutePath() + "/" + Long.toString(groupId) + ".png");
        if (imageFile.exists()) {
            try {
                return imageFile.toURL().toString();
            } catch (MalformedURLException e) {
                if (log.isDebugEnabled())
                    e.printStackTrace();
            }/*from   w w w  .ja  v  a  2s  .co  m*/
        }
        imageFile = new File(baseDirFile.getAbsolutePath() + "/" + Long.toString(groupId) + ".jpeg");
        if (imageFile.exists()) {
            try {
                return imageFile.toURL().toString();
            } catch (MalformedURLException e) {
                if (log.isDebugEnabled())
                    e.printStackTrace();
            }
        }
        imageFile = new File(baseDirFile.getAbsolutePath() + "/" + Long.toString(groupId) + ".jpg");
        if (imageFile.exists()) {
            try {
                return imageFile.toURL().toString();
            } catch (MalformedURLException e) {
                if (log.isDebugEnabled())
                    e.printStackTrace();
            }
        }
        imageFile = new File(baseDirFile.getAbsolutePath() + "/" + Long.toString(groupId) + ".gif");
        if (imageFile.exists()) {
            try {
                return imageFile.toURL().toString();
            } catch (MalformedURLException e) {
                if (log.isDebugEnabled())
                    e.printStackTrace();
            }
        }
    }
    return imageurl;
}

From source file:com.liferay.lms.service.impl.CompetenceLocalServiceImpl.java

License:Open Source License

public void setBGImage(byte[] data, long groupId, String name) throws IOException {
    String baseDir = PropsUtil.get("liferay.home") + "/data/compimages";
    File baseDirFile = new File(baseDir);
    if (!baseDirFile.exists()) {
        baseDirFile.mkdir();/*from   ww w.j  av  a 2s  .  co  m*/
    }
    String fileExtension = name.substring(name.lastIndexOf('.'));
    File imageFile = new File(
            baseDirFile.getAbsolutePath() + "/" + Long.toString(groupId) + fileExtension.toLowerCase());
    /* Cambios de Miguel que borra imagenes */
    String[] nameOfFiles = baseDirFile.list();
    String[] aux = null;
    File fileToDelete = null;
    for (int i = 0; i < nameOfFiles.length; i++) {
        aux = nameOfFiles[i].split("\\.");
        if (aux[0].equals(Long.toString(groupId))) {
            fileToDelete = new File(
                    baseDirFile.getAbsolutePath() + "/" + Long.toString(groupId) + "." + aux[1]);
            fileToDelete.delete();
            fileExtension = null;
        }
    }
    /* Fin de cambios de Miguel */

    imageFile.createNewFile();
    FileOutputStream fos = new FileOutputStream(imageFile);
    fos.write(data);
    fos.close();
}

From source file:com.liferay.lms.service.impl.CourseLocalServiceImpl.java

License:Open Source License

public Course addCourse(String title, String description, String summary, String friendlyURL, Locale locale,
        java.util.Date createDate, java.util.Date startDate, java.util.Date endDate, long layoutSetPrototypeId,
        int typesite, long CourseEvalId, long calificationType, int maxUsers, ServiceContext serviceContext,
        boolean isfromClone) throws SystemException, PortalException {
    LmsPrefs lmsPrefs = lmsPrefsLocalService.getLmsPrefsIni(serviceContext.getCompanyId());
    long userId = serviceContext.getUserId();
    Course course = coursePersistence.create(counterLocalService.increment(Course.class.getName()));
    try {//  w ww.  ja  va 2  s  . c  om

        //Se asegura que la longitud de friendlyURL no supere el maximo
        int maxLength = GetterUtil.getInteger(
                ModelHintsUtil.getHints(Group.class.getName(), "friendlyURL").get("max-length"),
                GetterUtil.getInteger(ModelHintsConstants.TEXT_MAX_LENGTH));

        if (Validator.isNull(friendlyURL)) {
            friendlyURL = StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(title);
            if (friendlyURL.length() > maxLength) {
                friendlyURL = friendlyURL.substring(0, maxLength);
            }
            for (int i = 0;; i++) {
                Group exist = groupLocalService.fetchFriendlyURLGroup(serviceContext.getCompanyId(),
                        friendlyURL);
                if (Validator.isNotNull(exist)) {
                    String iString = String.valueOf(i);
                    if (friendlyURL.length() + iString.length() > maxLength) {
                        if (iString.length() > maxLength) {
                            throw new SystemException();
                        }
                        friendlyURL = friendlyURL.substring(0, maxLength - iString.length()) + iString;
                    } else {
                        friendlyURL = friendlyURL + iString;
                    }
                } else {
                    break;
                }
            }
        }

        friendlyURL = StringPool.SLASH + friendlyURL.replaceAll("[^a-zA-Z0-9_-]+", "");

        course.setCompanyId(serviceContext.getCompanyId());
        course.setGroupId(serviceContext.getScopeGroupId());
        course.setUserId(userId);
        course.setUserName(userLocalService.getUser(userId).getFullName());
        course.setFriendlyURL(friendlyURL);
        course.setDescription(description, locale);
        course.setTitle(title, locale);
        course.setCreateDate(createDate);
        course.setModifiedDate(createDate);
        course.setStartDate(startDate);
        course.setEndDate(endDate);
        course.setStatus(WorkflowConstants.STATUS_APPROVED);
        course.setExpandoBridgeAttributes(serviceContext);
        course.setCourseEvalId(CourseEvalId);
        course.setCalificationType(calificationType);
        course.setMaxusers(maxUsers);

        course = LmsLocaleUtil.checkDefaultLocale(Course.class, course, "description");
        //creating group
        Group group = groupLocalService.addGroup(
                userLocalService.getDefaultUser(serviceContext.getCompanyId()).getUserId(), null, 0, title,
                summary, typesite, friendlyURL, true, true, serviceContext);
        course.setGroupCreatedId(group.getGroupId());
        course.setFriendlyURL(group.getFriendlyURL());

        coursePersistence.update(course, true);

        resourceLocalService.addResources(serviceContext.getCompanyId(), serviceContext.getScopeGroupId(),
                userId, Course.class.getName(), course.getPrimaryKey(), false, true, true);
        AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, course.getGroupId(),
                Course.class.getName(), course.getCourseId(), course.getUuid(), 0,
                serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), true, null, null,
                new java.util.Date(System.currentTimeMillis()), null, ContentTypes.TEXT_HTML, course.getTitle(),
                course.getDescription(locale), summary, null, null, 0, 0, null, false);
        assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(),
                serviceContext.getAssetLinkEntryIds(), AssetLinkConstants.TYPE_RELATED);

        //Aadimos el rol Teacher al usuario que crea el blog
        long[] usuarios = new long[] { userId };
        boolean teacherRoleToCreator = GetterUtil
                .getBoolean(PropsUtil.get("lms.course.add.teacherRoleToCreator"));
        boolean editorRoleToCreator = GetterUtil
                .getBoolean(PropsUtil.get("lms.course.add.editorRoleToCreator"));

        if (teacherRoleToCreator || editorRoleToCreator) {
            groupLocalService.addUserGroups(userId, new long[] { group.getGroupId() });
        }

        if (teacherRoleToCreator) {
            userGroupRoleLocalService.addUserGroupRoles(usuarios, course.getGroupCreatedId(),
                    lmsPrefs.getTeacherRole());
        }

        if (editorRoleToCreator) {
            userGroupRoleLocalService.addUserGroupRoles(usuarios, course.getGroupCreatedId(),
                    lmsPrefs.getEditorRole());
        }
        LayoutSetPrototype lsProto = layoutSetPrototypeLocalService.getLayoutSetPrototype(layoutSetPrototypeId);
        //importLayouts(getAdministratorUser(serviceContext.getCompanyId()).getUserId(), group, lsProto);

        importLayouts(userId, group, lsProto);

        CourseEval courseEval = new CourseEvalRegistry().getCourseEval(CourseEvalId);
        if (courseEval != null) {
            courseEval.setExtraContent(course, "ADD_COURSE", serviceContext);
        }

        /* activamos social activity para la comunidad creada */
        List<SocialActivitySetting> actSettings = SocialActivitySettingLocalServiceUtil
                .getActivitySettings(lsProto.getGroup().getGroupId());
        for (SocialActivitySetting actSetting : actSettings) {
            //Activamos las activity settings que estn activadas en la plantilla
            SocialActivitySettingLocalServiceUtil.updateActivitySetting(group.getGroupId(),
                    actSetting.getClassName(), true);
            List<SocialActivityDefinition> sads = SocialActivitySettingServiceUtil
                    .getActivityDefinitions(lsProto.getGroup().getGroupId(), actSetting.getClassName());
            for (SocialActivityDefinition sad : sads) {

                java.util.Collection<SocialActivityCounterDefinition> sacdl = sad
                        .getActivityCounterDefinitions();
                List<SocialActivityCounterDefinition> sacdlnew = new java.util.ArrayList<SocialActivityCounterDefinition>();
                for (SocialActivityCounterDefinition sacd : sacdl) {
                    SocialActivityCounterDefinition sacdn = sacd.clone();
                    sacdlnew.add(sacdn);
                }
                SocialActivitySettingServiceUtil.updateActivitySettings(group.getGroupId(),
                        actSetting.getClassName(), sad.getActivityType(), sacdlnew);
            }
        }
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Course.class);
        indexer.reindex(course);
    } catch (PortalException e) {
        if (log.isInfoEnabled()) {
            log.info("CourseLocalServiceImpl.addCourse(): " + e + "message: " + e.getMessage());
        }
        throw e;
    } catch (Exception e) {
        if (log.isInfoEnabled()) {
            log.info("CourseLocalServiceImpl.addCourse(): " + e + "message: " + e.getMessage());
        }
        throw new PortalException(e.getMessage());

    }

    // METODO METIDO POR MIGUEL
    if (!isfromClone) {
        Module newModule;
        try {

            newModule = ModuleLocalServiceUtil
                    .createModule(CounterLocalServiceUtil.increment(Module.class.getName()));
            newModule.setTitle(LanguageUtil.get(locale, "com.liferay.lms.model.module"), locale);
            newModule.setDescription(LanguageUtil.get(locale, "description"), locale);

            newModule.setCompanyId(course.getCompanyId());
            newModule.setGroupId(course.getGroupCreatedId());
            newModule.setUserId(course.getUserId());
            newModule.setOrdern(newModule.getModuleId());

            /*
            Calendar start = Calendar.getInstance();
            start.setTimeInMillis(module.getStartDate().getTime() + TimeUnit.MILLISECONDS.convert(days, TimeUnit.DAYS));
            Calendar stop = Calendar.getInstance();
            stop.setTimeInMillis(module.getEndDate().getTime() + TimeUnit.MILLISECONDS.convert(days, TimeUnit.DAYS));
            */

            //System.out.println(" startDate: "+ start.getTime() +"   -> "+module.getStartDate());
            //System.out.println(" stopDate : "+ stop.getTime()  +"   -> "+module.getEndDate());

            newModule.setStartDate(startDate);
            newModule.setEndDate(endDate);

            ModuleLocalServiceUtil.addModule(newModule);

            System.out.println("    + Module : " + newModule.getTitle(Locale.getDefault()) + "("
                    + newModule.getModuleId() + ")");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    ////////////////////////////
    //auditing
    AuditingLogFactory.audit(course.getCompanyId(), course.getGroupId(), Course.class.getName(),
            course.getCourseId(), userId, AuditConstants.ADD, null);
    return course;

}

From source file:com.liferay.lms.service.impl.SCORMContentLocalServiceImpl.java

License:Open Source License

public String getBaseDir() {
    String baseDir = PropsUtil.get("liferay.lms.scormdir");
    if (baseDir == null || baseDir.equals("")) {
        baseDir = PropsUtil.get("liferay.home") + "/data/scorms";
    }/*from ww  w. ja v a  2 s.  com*/
    return baseDir;
}

From source file:com.liferay.lms.service.impl.SCORMContentLocalServiceImpl.java

License:Open Source License

public String getBaseZipDir() {
    String baseDir = PropsUtil.get("liferay.lms.scormzipsdir");
    if (baseDir == null || baseDir.equals("")) {
        baseDir = PropsUtil.get("liferay.home") + "/data/scormszip";
    }/*  w w  w .j a v  a 2  s  .  c  om*/
    return baseDir;
}

From source file:com.liferay.lms.service.impl.SCORMContentLocalServiceImpl.java

License:Open Source License

public String getDirScormzipPath(SCORMContent scocon) {
    String baseDir = PropsUtil.get("liferay.lms.scormzipsdir");
    if (baseDir == null || baseDir.equals("")) {
        baseDir = PropsUtil.get("liferay.home") + "/data/scormszip";
    }/* w ww . j a  va 2s  . c om*/
    return baseDir + "/" + Long.toString(scocon.getCompanyId()) + "/" + Long.toString(scocon.getGroupId()) + "/"
            + scocon.getUuid();
}

From source file:com.liferay.lms.service.impl.SCORMContentLocalServiceImpl.java

License:Open Source License

public String getDirScormPath(SCORMContent scocon) {
    String baseDir = PropsUtil.get("liferay.lms.scormdir");
    if (baseDir == null || baseDir.equals("")) {
        baseDir = PropsUtil.get("liferay.home") + "/data/scorms";
    }/*from  www.  ja  v  a2  s . c  om*/
    return baseDir + "/" + Long.toString(scocon.getCompanyId()) + "/" + Long.toString(scocon.getGroupId()) + "/"
            + scocon.getUuid();
}

From source file:com.liferay.lmssa.service.ClpSerializer.java

License:Open Source License

public static String getServletContextName() {
    if (Validator.isNotNull(_servletContextName)) {
        return _servletContextName;
    }//from   ww  w  .j  a  v a 2  s  . c o  m

    synchronized (ClpSerializer.class) {
        if (Validator.isNotNull(_servletContextName)) {
            return _servletContextName;
        }

        try {
            ClassLoader classLoader = ClpSerializer.class.getClassLoader();

            Class<?> portletPropsClass = classLoader.loadClass("com.liferay.util.portlet.PortletProps");

            Method getMethod = portletPropsClass.getMethod("get", new Class<?>[] { String.class });

            String portletPropsServletContextName = (String) getMethod.invoke(null,
                    "ActivityManager-portlet-deployment-context");

            if (Validator.isNotNull(portletPropsServletContextName)) {
                _servletContextName = portletPropsServletContextName;
            }
        } catch (Throwable t) {
            if (_log.isInfoEnabled()) {
                _log.info("Unable to locate deployment context from portlet properties");
            }
        }

        if (Validator.isNull(_servletContextName)) {
            try {
                String propsUtilServletContextName = PropsUtil
                        .get("ActivityManager-portlet-deployment-context");

                if (Validator.isNotNull(propsUtilServletContextName)) {
                    _servletContextName = propsUtilServletContextName;
                }
            } catch (Throwable t) {
                if (_log.isInfoEnabled()) {
                    _log.info("Unable to locate deployment context from portal properties");
                }
            }
        }

        if (Validator.isNull(_servletContextName)) {
            _servletContextName = "ActivityManager-portlet";
        }

        return _servletContextName;
    }
}

From source file:com.liferay.mail.service.ClpSerializer.java

License:Open Source License

public static String getServletContextName() {
    if (Validator.isNotNull(_servletContextName)) {
        return _servletContextName;
    }// ww w  .j a v a2 s. c om

    synchronized (ClpSerializer.class) {
        if (Validator.isNotNull(_servletContextName)) {
            return _servletContextName;
        }

        try {
            ClassLoader classLoader = ClpSerializer.class.getClassLoader();

            Class<?> portletPropsClass = classLoader.loadClass("com.liferay.util.portlet.PortletProps");

            Method getMethod = portletPropsClass.getMethod("get", new Class<?>[] { String.class });

            String portletPropsServletContextName = (String) getMethod.invoke(null,
                    "mail-portlet-deployment-context");

            if (Validator.isNotNull(portletPropsServletContextName)) {
                _servletContextName = portletPropsServletContextName;
            }
        } catch (Throwable t) {
            if (_log.isInfoEnabled()) {
                _log.info("Unable to locate deployment context from portlet properties");
            }
        }

        if (Validator.isNull(_servletContextName)) {
            try {
                String propsUtilServletContextName = PropsUtil.get("mail-portlet-deployment-context");

                if (Validator.isNotNull(propsUtilServletContextName)) {
                    _servletContextName = propsUtilServletContextName;
                }
            } catch (Throwable t) {
                if (_log.isInfoEnabled()) {
                    _log.info("Unable to locate deployment context from portal properties");
                }
            }
        }

        if (Validator.isNull(_servletContextName)) {
            _servletContextName = "mail-portlet";
        }

        return _servletContextName;
    }
}

From source file:com.liferay.marketplace.service.ClpSerializer.java

License:Open Source License

public static String getServletContextName() {
    if (Validator.isNotNull(_servletContextName)) {
        return _servletContextName;
    }// w ww.j av a2  s .  c  o  m

    synchronized (ClpSerializer.class) {
        if (Validator.isNotNull(_servletContextName)) {
            return _servletContextName;
        }

        try {
            ClassLoader classLoader = ClpSerializer.class.getClassLoader();

            Class<?> portletPropsClass = classLoader.loadClass("com.liferay.util.portlet.PortletProps");

            Method getMethod = portletPropsClass.getMethod("get", new Class<?>[] { String.class });

            String portletPropsServletContextName = (String) getMethod.invoke(null,
                    "marketplace-portlet-deployment-context");

            if (Validator.isNotNull(portletPropsServletContextName)) {
                _servletContextName = portletPropsServletContextName;
            }
        } catch (Throwable t) {
            if (_log.isInfoEnabled()) {
                _log.info("Unable to locate deployment context from portlet properties");
            }
        }

        if (Validator.isNull(_servletContextName)) {
            try {
                String propsUtilServletContextName = PropsUtil.get("marketplace-portlet-deployment-context");

                if (Validator.isNotNull(propsUtilServletContextName)) {
                    _servletContextName = propsUtilServletContextName;
                }
            } catch (Throwable t) {
                if (_log.isInfoEnabled()) {
                    _log.info("Unable to locate deployment context from portal properties");
                }
            }
        }

        if (Validator.isNull(_servletContextName)) {
            _servletContextName = "marketplace-portlet";
        }

        return _servletContextName;
    }
}