Search in sources :

Example 6 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class AdminGeneralAction method sendmail.

@Execute
public HtmlResponse sendmail(final MailForm form) {
    validate(form, messages -> {
    }, () -> {
        return asHtml(path_AdminGeneral_AdminGeneralJsp);
    });
    final String[] toAddresses = form.notificationTo.split(",");
    final Map<String, Object> dataMap = new HashMap<>();
    dataMap.put("hostname", systemHelper.getHostname());
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
    try {
        TestmailPostcard.droppedInto(postbox, postcard -> {
            postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
            postcard.addReplyTo(fessConfig.getMailReturnPath());
            stream(toAddresses).of(stream -> stream.forEach(address -> {
                postcard.addTo(address);
            }));
            BeanUtil.copyMapToBean(dataMap, postcard);
        });
        saveInfo(messages -> messages.addSuccessSendTestmail(GLOBAL));
        updateProperty(Constants.NOTIFICATION_TO_PROPERTY, form.notificationTo);
        systemProperties.store();
    } catch (final Exception e) {
        logger.warn("Failed to send a test mail.", e);
        saveError(messages -> messages.addErrorsFailedToSendTestmail(GLOBAL));
    }
    return redirectByParam(AdminGeneralAction.class, "notificationTo", form.notificationTo);
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) DynamicProperties(org.codelibs.core.misc.DynamicProperties) Logger(org.slf4j.Logger) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) ArrayList(java.util.ArrayList) Postbox(org.lastaflute.core.mail.Postbox) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) TestmailPostcard(org.codelibs.fess.mylasta.mail.TestmailPostcard) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) HashMap(java.util.HashMap) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Execute(org.lastaflute.web.Execute)

Example 7 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class AdminDesignAction method edit.

// -----------------------------------------------------
//                                                 Edit
//                                                ------
@Execute
public HtmlResponse edit(final EditForm form) {
    final String jspType = "view";
    final File jspFile = getJspFile(form.fileName, jspType);
    try {
        form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
    } catch (final UnsupportedEncodingException e) {
        throw new FessSystemException("Invalid encoding", e);
    }
    saveToken();
    return asEditHtml();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) File(java.io.File) FessSystemException(org.codelibs.fess.exception.FessSystemException) Execute(org.lastaflute.web.Execute)

Example 8 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class AdminDesignAction method update.

@Execute
public HtmlResponse update(final EditForm form) {
    final String jspType = "view";
    final File jspFile = getJspFile(form.fileName, jspType);
    if (form.content == null) {
        form.content = StringUtil.EMPTY;
    }
    validate(form, messages -> {
    }, () -> asEditHtml());
    verifyToken(() -> asEditHtml());
    try {
        write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
        saveInfo(messages -> messages.addSuccessUpdateDesignJspFile(GLOBAL, systemHelper.getDesignJspFileName(form.fileName)));
    } catch (final Exception e) {
        logger.error("Failed to update {}", form.fileName, e);
        throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), () -> asListHtml());
    }
    return redirect(getClass());
}
Also used : Constants(org.codelibs.fess.Constants) Logger(org.slf4j.Logger) FessSystemException(org.codelibs.fess.exception.FessSystemException) ResourceUtil(org.codelibs.core.io.ResourceUtil) OptionalEntity(org.dbflute.optional.OptionalEntity) StringUtil(org.codelibs.core.lang.StringUtil) LoggerFactory(org.slf4j.LoggerFactory) FileUtils(org.apache.commons.io.FileUtils) FileInputStream(java.io.FileInputStream) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) File(java.io.File) ArrayList(java.util.ArrayList) ActionResponse(org.lastaflute.web.response.ActionResponse) List(java.util.List) StreamResponse(org.lastaflute.web.response.StreamResponse) FileUtil(org.codelibs.core.io.FileUtil) Locale(java.util.Locale) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) File(java.io.File) FessSystemException(org.codelibs.fess.exception.FessSystemException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Execute(org.lastaflute.web.Execute)

Example 9 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class AdminWizardAction method startCrawling.

@Execute
public HtmlResponse startCrawling(final StartCrawlingForm form) {
    verifyToken(() -> asIndexHtml());
    if (!processHelper.isProcessRunning()) {
        final List<ScheduledJob> scheduledJobList = scheduledJobService.getCrawlerJobList();
        final JobManager jobManager = ComponentUtil.getJobManager();
        for (final ScheduledJob scheduledJob : scheduledJobList) {
            jobManager.findJobByUniqueOf(LaJobUnique.of(scheduledJob.getId())).ifPresent(job -> {
                job.launchNow();
            });
        }
        saveInfo(messages -> messages.addSuccessStartCrawlProcess(GLOBAL));
    } else {
        saveError(messages -> messages.addErrorsFailedToStartCrawlProcess(GLOBAL));
    }
    return redirect(AdminWizardAction.class);
}
Also used : ScheduledJob(org.codelibs.fess.es.config.exentity.ScheduledJob) JobManager(org.lastaflute.job.JobManager) Execute(org.lastaflute.web.Execute)

Example 10 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminAccesstokenAction method post$setting.

// POST /api/admin/accesstoken/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final AccessToken accessToken = getAccessToken(body).map(entity -> {
        try {
            accessTokenService.store(entity);
        } catch (final Exception e) {
            throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
        }
        return entity;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
        return null;
    });
    return asJson(new ApiUpdateResponse().id(accessToken.getId()).created(false).status(Status.OK).result());
}
Also used : AccessTokenPager(org.codelibs.fess.app.pager.AccessTokenPager) AdminAccesstokenAction.getAccessToken(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction.getAccessToken) Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) AccessTokenService(org.codelibs.fess.app.service.AccessTokenService) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) AdminAccesstokenAction(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction) ComponentUtil(org.codelibs.fess.util.ComponentUtil) AccessToken(org.codelibs.fess.es.config.exentity.AccessToken) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) ApiConfigsResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigsResponse) AdminAccesstokenAction.getAccessToken(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction.getAccessToken) AccessToken(org.codelibs.fess.es.config.exentity.AccessToken) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Aggregations

Execute (org.lastaflute.web.Execute)125 ApiResult (org.codelibs.fess.app.web.api.ApiResult)94 Resource (javax.annotation.Resource)83 CrudMode (org.codelibs.fess.app.web.CrudMode)77 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)71 JsonResponse (org.lastaflute.web.response.JsonResponse)71 Collectors (java.util.stream.Collectors)70 List (java.util.List)51 InputStream (java.io.InputStream)39 File (java.io.File)35 StreamResponse (org.lastaflute.web.response.StreamResponse)34 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)32 Status (org.codelibs.fess.app.web.api.ApiResult.Status)31 Constants (org.codelibs.fess.Constants)26 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)26 StringUtil (org.codelibs.core.lang.StringUtil)24 ComponentUtil (org.codelibs.fess.util.ComponentUtil)23 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)22 HtmlResponse (org.lastaflute.web.response.HtmlResponse)20 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)14