Search in sources :

Example 1 with ApplicationConfiguration

use of com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration in project cia by Hack23.

the class AdminApplicationConfigurationPageModContentFactoryImpl method createContent.

@Secured({ "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout content = createPanelContent();
    final String pageId = getPageId(parameters);
    final int pageNr = getPageNr(parameters);
    getMenuItemFactory().createMainPageMenuBar(menuBar);
    LabelFactory.createHeader2Label(content, ADMIN_APPLICATION_CONFIGURATION);
    final DataContainer<ApplicationConfiguration, Long> dataContainer = getApplicationManager().getDataContainer(ApplicationConfiguration.class);
    final List<ApplicationConfiguration> pageOrderBy = dataContainer.getPageOrderBy(pageNr, DEFAULT_RESULTS_PER_PAGE, ApplicationConfiguration_.configurationGroup);
    createPagingControls(content, NAME, pageId, dataContainer.getSize(), pageNr, DEFAULT_RESULTS_PER_PAGE);
    getGridFactory().createBasicBeanItemGrid(content, ApplicationConfiguration.class, pageOrderBy, APPLICATION_CONFIGURATION, COLUMN_ORDER, HIDE_COLUMNS, new PageItemPropertyClickListener(AdminViews.ADMIN_APPLICATIONS_CONFIGURATION_VIEW_NAME, "hjid"), null, null);
    if (pageId != null && !pageId.isEmpty()) {
        final ApplicationConfiguration applicationConfiguration = dataContainer.load(Long.valueOf(pageId));
        if (applicationConfiguration != null) {
            final VerticalLayout leftLayout = new VerticalLayout();
            leftLayout.setSizeFull();
            final VerticalLayout rightLayout = new VerticalLayout();
            rightLayout.setSizeFull();
            final HorizontalLayout horizontalLayout = new HorizontalLayout();
            horizontalLayout.setWidth(ContentSize.FULL_SIZE);
            content.addComponent(horizontalLayout);
            horizontalLayout.addComponent(leftLayout);
            horizontalLayout.addComponent(rightLayout);
            getFormFactory().addFormPanelTextFields(leftLayout, applicationConfiguration, ApplicationConfiguration.class, AS_LIST);
            final UpdateApplicationConfigurationRequest request = new UpdateApplicationConfigurationRequest();
            request.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
            request.setApplicationConfigurationId(applicationConfiguration.getHjid());
            request.setConfigTitle(applicationConfiguration.getConfigTitle());
            request.setConfigDescription(applicationConfiguration.getConfigDescription());
            request.setComponentTitle(applicationConfiguration.getConfigTitle());
            request.setComponentDescription(applicationConfiguration.getComponentDescription());
            request.setPropertyValue(applicationConfiguration.getPropertyValue());
            final ClickListener buttonListener = new UpdateApplicationConfigurationClickListener(request);
            final Panel updateFormPanel = new Panel();
            updateFormPanel.setSizeFull();
            rightLayout.addComponent(updateFormPanel);
            final FormLayout updateFormContent = new FormLayout();
            updateFormPanel.setContent(updateFormContent);
            getFormFactory().addRequestInputFormFields(updateFormContent, request, UpdateApplicationConfigurationRequest.class, AS_LIST2, UPDATE_CONFIGURATION, buttonListener);
        }
    }
    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_APPLICATION_CONFIGURATION_VIEW, ApplicationEventGroup.ADMIN, NAME, null, pageId);
    return content;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) UpdateApplicationConfigurationClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.UpdateApplicationConfigurationClickListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Panel(com.vaadin.ui.Panel) UpdateApplicationConfigurationRequest(com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationRequest) PageItemPropertyClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener) VerticalLayout(com.vaadin.ui.VerticalLayout) ApplicationConfiguration(com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration) ClickListener(com.vaadin.ui.Button.ClickListener) PageItemPropertyClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener) UpdateApplicationConfigurationClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.UpdateApplicationConfigurationClickListener) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with ApplicationConfiguration

use of com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration in project cia by Hack23.

the class ApplicationConfigurationServiceImpl method checkValueOrLoadDefault.

@Override
public ApplicationConfiguration checkValueOrLoadDefault(final String configTitle, final String configDescription, final ConfigurationGroup configurationGroup, final String component, final String componentTitle, final String componentDescription, final String propertyId, final String propertyValue) {
    final List<ApplicationConfiguration> findListByProperty = applicationConfigurationDAO.findListByProperty(new Object[] { component, configurationGroup, propertyId }, ApplicationConfiguration_.component, ApplicationConfiguration_.configurationGroup, ApplicationConfiguration_.propertyId);
    if (findListByProperty.isEmpty()) {
        final ApplicationConfiguration applicationConfiguration = new ApplicationConfiguration();
        applicationConfiguration.setCreatedDate(new Date());
        applicationConfiguration.setUpdatedDate(new Date());
        applicationConfiguration.setConfigTitle(configTitle);
        applicationConfiguration.setConfigDescription(configDescription);
        applicationConfiguration.setConfigurationGroup(configurationGroup);
        applicationConfiguration.setComponent(component);
        applicationConfiguration.setComponentTitle(componentTitle);
        applicationConfiguration.setComponentDescription(componentDescription);
        applicationConfiguration.setPropertyId(propertyId);
        applicationConfiguration.setPropertyValue(propertyValue);
        applicationConfigurationDAO.persist(applicationConfiguration);
        return applicationConfiguration;
    } else {
        return findListByProperty.get(0);
    }
}
Also used : ApplicationConfiguration(com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration) Date(java.util.Date)

Example 3 with ApplicationConfiguration

use of com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration in project cia by Hack23.

the class WorldBankDataWorkGeneratorImpl method generateWorkOrders.

@Override
public void generateWorkOrders() {
    final ApplicationConfiguration importDataForCountries = applicationConfigurationService.checkValueOrLoadDefault("Countries to import data from worldbank (isocode) alt comma separated list", "Load worldbank data for countries", ConfigurationGroup.AGENT, WorldBankCountryWorkGeneratorImpl.class.getSimpleName(), "Worldbank country data loading", "Responsible import worldlbank country data", "agent.worldbank.country.data.loadCountries", "SE,NO,DK,FI,GB,US");
    final List<IndicatorElement> indicatorlist = getImportService().getAllIndicators();
    final Map<String, String> currentSaved = getImportService().getWorldBankDataMap();
    for (final String country : getImportService().getWorldBankCountryMap().keySet()) {
        if (StringUtils.containsIgnoreCase(importDataForCountries.getPropertyValue(), country)) {
            for (final IndicatorElement indicator : indicatorlist) {
                sendCountryIndicatorWorkOrder(currentSaved, indicator, country);
            }
        }
    }
}
Also used : ApplicationConfiguration(com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration) IndicatorElement(com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement)

Example 4 with ApplicationConfiguration

use of com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration in project cia by Hack23.

the class LoginBlockedAccessImpl method blockByUserFailedLoginAttempts.

/**
 * Block by user failed login attempts.
 *
 * @param email
 *            the email
 * @param loginBlockResultImpl
 *            the login block result impl
 */
private void blockByUserFailedLoginAttempts(final String email, final LoginBlockResultImpl loginBlockResultImpl) {
    final UserAccount userExist = userDAO.findFirstByProperty(UserAccount_.email, email);
    if (userExist != null) {
        final ApplicationConfiguration maxLoginAttemptsByUser = applicationConfigurationService.checkValueOrLoadDefault(MAX_FAILED_LOGIN_ATTEMPTS_RECENT_HOUR_PER_USER, BLOCKS_ANY_LOGIN_ATTEMPTS_AFTER_THIS_NUMBER_IS_REACHED, ConfigurationGroup.AUTHENTICATION, LoginBlockedAccessImpl.class.getSimpleName(), LOGIN_BLOCKER, BLOCKS_LOGIN_ATTEMPTS, APPLICATION_AUTHENTICATION_ALLOW_MAX_RECENT_FAILED_LOGINS_BY_USER, DEFAULT_MAX_LOGIN_ATTEMPTS);
        final List<ApplicationActionEvent> failedLoginsByThisUser = applicationActionEventDAO.findListByProperty(new Object[] { email, ApplicationOperationType.AUTHENTICATION, ServiceResult.FAILURE.toString() }, ApplicationActionEvent_.elementId, ApplicationActionEvent_.applicationOperation, ApplicationActionEvent_.applicationMessage);
        final Date oneHourAgo = new Date(System.currentTimeMillis() - ONE_HOUR);
        final Map<Boolean, List<ApplicationActionEvent>> recentOldLoginAttemptsMap = failedLoginsByThisUser.stream().collect(Collectors.groupingBy((final ApplicationActionEvent x) -> x.getCreatedDate().after(oneHourAgo)));
        final List<ApplicationActionEvent> recentFailedLogins = recentOldLoginAttemptsMap.get(Boolean.TRUE);
        if (recentFailedLogins != null && recentFailedLogins.size() > NumberUtils.toInt(maxLoginAttemptsByUser.getPropertyValue(), DEFAULT_MAX_LOGINS)) {
            loginBlockResultImpl.setBlocked(true);
            loginBlockResultImpl.addMessages(BLOCKED_BY_MORE_THAN_5_RECENT_LOGIN_ATTEMPTS_BY_THIS_USER);
        }
    }
}
Also used : ApplicationActionEvent(com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent) ArrayList(java.util.ArrayList) List(java.util.List) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) ApplicationConfiguration(com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration) Date(java.util.Date)

Example 5 with ApplicationConfiguration

use of com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration in project cia by Hack23.

the class AbstractServiceFunctionalIntegrationTest method configureMailServer.

/**
 * Configure mail server.
 *
 * @param createTestApplicationSession
 *            the create test application session
 * @return the simple smtp server
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
protected final SimpleSmtpServer configureMailServer(CreateApplicationSessionRequest createTestApplicationSession) throws IOException {
    final SimpleSmtpServer dumbster = SimpleSmtpServer.start(SimpleSmtpServer.AUTO_SMTP_PORT);
    setAuthenticatedAdminuser();
    createTestApplicationSession = createTestApplicationSession();
    final ApplicationConfiguration sendEmail = applicationConfigurationService.checkValueOrLoadDefault("Email configuration send emails", "Send email", ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), "Send email", "Responsible for sending email", "application.email.send.email", "false");
    final ApplicationConfiguration smtpPort = applicationConfigurationService.checkValueOrLoadDefault("Email configuration smtp port", "Smtp port", ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), "Smtp port", "Responsible for sending email", "application.email.smtp.port", "587");
    final ApplicationConfiguration smtpHost = applicationConfigurationService.checkValueOrLoadDefault("Email configuration smtp host", "Smtp host", ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), "Smtp host", "Responsible for sending email", "application.email.smtp.host", "localhost");
    updateApplicationConfiguration(createTestApplicationSession, sendEmail, "true");
    updateApplicationConfiguration(createTestApplicationSession, smtpPort, Integer.toString(dumbster.getPort()));
    updateApplicationConfiguration(createTestApplicationSession, smtpHost, "localhost");
    return dumbster;
}
Also used : EmailServiceImpl(com.hack23.cia.service.impl.email.EmailServiceImpl) SimpleSmtpServer(com.dumbster.smtp.SimpleSmtpServer) ApplicationConfiguration(com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration)

Aggregations

ApplicationConfiguration (com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration)14 Date (java.util.Date)4 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)3 UpdateApplicationConfigurationRequest (com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationRequest)3 UpdateApplicationConfigurationResponse (com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationResponse)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Secured (org.springframework.security.access.annotation.Secured)3 ApplicationActionEvent (com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent)2 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)2 EmailServiceImpl (com.hack23.cia.service.impl.email.EmailServiceImpl)2 List (java.util.List)2 SimpleSmtpServer (com.dumbster.smtp.SimpleSmtpServer)1 IndicatorElement (com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement)1 ApplicationSession (com.hack23.cia.model.internal.application.system.impl.ApplicationSession)1 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)1 RegisterUserResponse (com.hack23.cia.service.api.action.application.RegisterUserResponse)1 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)1 PageItemPropertyClickListener (com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener)1 UpdateApplicationConfigurationClickListener (com.hack23.cia.web.impl.ui.application.views.pageclicklistener.UpdateApplicationConfigurationClickListener)1