Search in sources :

Example 1 with ClientApp

use of org.alfresco.repo.client.config.ClientAppConfig.ClientApp in project alfresco-repository by Alfresco.

the class ClientAppConfigTest method testClients.

@Test
public void testClients() throws Exception {
    Map<String, ClientApp> clients = clientAppConfig.getClients();
    assertNotNull(clients);
    assertEquals("Incorrect number of clients", 4, clients.size());
    // loaded from org/alfresco/repo/client/config/test-repo-clients-apps.properties
    ClientApp client1 = clientAppConfig.getClient("test-client1");
    assertNotNull(client1);
    assertEquals("test-client1", client1.getName());
    assertEquals("http://localhost:8081/test-client1/o", client1.getProperty("sharedLinkBaseUrl"));
    assertEquals("http://localhost:8081/test-client1", client1.getTemplateAssetsUrl());
    // loaded from org/alfresco/repo/client/config/test-repo-clients-apps.properties and overridden by
    // org/alfresco/repo/client/config/test-global-properties.properties
    ClientApp client2 = clientAppConfig.getClient("test-client2");
    assertNotNull(client2);
    assertEquals("test-client2", client2.getName());
    assertEquals("https://127.0.0.1:8082/test-client2/t", client2.getProperty("sharedLinkBaseUrl"));
    assertEquals("https://127.0.0.1:8082/test-client2", client2.getTemplateAssetsUrl());
    // loaded from org/alfresco/repo/client/config/test-global-properties.properties
    ClientApp client3 = clientAppConfig.getClient("test-client5");
    assertNotNull(client3);
    assertEquals("test-client5", client3.getName());
    assertEquals("http://localhost:8085/test-client5/f", client3.getProperty("myProp1"));
    assertEquals("http://localhost:8085/test-client5", client3.getProperty("myProp2"));
    assertEquals("test prop3", client3.getProperty("myProp3"));
    assertEquals("test prop4", client3.getProperty("myProp4"));
    assertEquals("test prop5", client3.getProperty("myProp5-with-hyphen"));
    assertNull(client3.getTemplateAssetsUrl());
    // loaded from org/alfresco/repo/client/config/test-global-properties.properties
    ClientApp client4 = clientAppConfig.getClient("test-client11");
    assertNotNull(client4);
    assertEquals("test-client11", client4.getName());
    assertEquals("http://localhost:8811/test-client11/t", client4.getProperty("myClientRequiredConfigUrl"));
    assertNull(client4.getTemplateAssetsUrl());
    // Try to add a property into an unmodifiable map
    try {
        client4.getProperties().put("newProperty", " test value");
        fail("Shouldn't be able to modify the client's processed properties.");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
    // Try to add a client into an unmodifiable map
    ClientApp newClient = new ClientApp("testClient" + System.currentTimeMillis(), "http://localhost:8085/testclient", Collections.singletonMap("sharedLinkBaseUrl", "http://localhost:8085/test-client/s"));
    try {
        clients.put(newClient.getName(), newClient);
        fail("Shouldn't be able to modify the clients map.");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
}
Also used : ClientApp(org.alfresco.repo.client.config.ClientAppConfig.ClientApp) Test(org.junit.Test)

Example 2 with ClientApp

use of org.alfresco.repo.client.config.ClientAppConfig.ClientApp in project alfresco-repository by Alfresco.

the class ResetPasswordServiceImpl method getClientAppConfig.

@Override
public ClientApp getClientAppConfig(String clientName) {
    ParameterCheck.mandatoryString("clientName", clientName);
    ClientApp clientApp = clientAppConfig.getClient(clientName);
    if (clientApp == null) {
        throw new ClientAppNotFoundException("Client was not found [" + clientName + "]");
    }
    return clientApp;
}
Also used : ClientAppNotFoundException(org.alfresco.repo.client.config.ClientAppNotFoundException) ClientApp(org.alfresco.repo.client.config.ClientAppConfig.ClientApp)

Example 3 with ClientApp

use of org.alfresco.repo.client.config.ClientAppConfig.ClientApp in project alfresco-repository by Alfresco.

the class ResetPasswordServiceImpl method sendResetPasswordEmail.

@Override
public void sendResetPasswordEmail(DelegateExecution execution, String fallbackEmailTemplatePath, String emailSubject) {
    Map<String, Object> variables = execution.getVariables();
    final String userName = (String) variables.get(WorkflowModelResetPassword.WF_PROP_USERNAME_ACTIVITI);
    final String toEmail = (String) variables.get(WorkflowModelResetPassword.WF_PROP_USER_EMAIL_ACTIVITI);
    final String clientName = (String) variables.get(WorkflowModelResetPassword.WF_PROP_CLIENT_NAME_ACTIVITI);
    final String key = (String) variables.get(WorkflowModelResetPassword.WF_PROP_KEY_ACTIVITI);
    final String id = execution.getProcessInstanceId();
    final ClientApp clientApp = getClientAppConfig(clientName);
    Map<String, Serializable> emailTemplateModel = Collections.singletonMap(FTL_RESET_PASSWORD_URL, createResetPasswordUrl(clientApp, id, key));
    final String templatePath = emailHelper.getEmailTemplate(clientName, getResetPasswordEmailTemplate(clientApp), fallbackEmailTemplatePath);
    ResetPasswordEmailDetails emailRequest = new ResetPasswordEmailDetails().setUserName(userName).setUserEmail(toEmail).setTemplatePath(templatePath).setTemplateAssetsUrl(clientApp.getTemplateAssetsUrl()).setEmailSubject(emailSubject).setTemplateModel(emailTemplateModel);
    sendEmail(emailRequest);
}
Also used : Serializable(java.io.Serializable) ClientApp(org.alfresco.repo.client.config.ClientAppConfig.ClientApp)

Example 4 with ClientApp

use of org.alfresco.repo.client.config.ClientAppConfig.ClientApp in project alfresco-repository by Alfresco.

the class ResetPasswordServiceImpl method sendResetPasswordConfirmationEmail.

@Override
public void sendResetPasswordConfirmationEmail(DelegateExecution execution, String fallbackEmailTemplatePath, String emailSubject) {
    Map<String, Object> variables = execution.getVariables();
    final String userName = (String) variables.get(WorkflowModelResetPassword.WF_PROP_USERNAME_ACTIVITI);
    final String userEmail = (String) variables.get(WorkflowModelResetPassword.WF_PROP_USER_EMAIL_ACTIVITI);
    final String clientName = (String) variables.get(WorkflowModelResetPassword.WF_PROP_CLIENT_NAME_ACTIVITI);
    // Now notify the user
    final ClientApp clientApp = getClientAppConfig(clientName);
    Map<String, Serializable> emailTemplateModel = Collections.singletonMap(FTL_USER_NAME, userName);
    final String templatePath = emailHelper.getEmailTemplate(clientName, getConfirmResetPasswordEmailTemplate(clientApp), fallbackEmailTemplatePath);
    ResetPasswordEmailDetails emailRequest = new ResetPasswordEmailDetails().setUserName(userName).setUserEmail(userEmail).setTemplatePath(templatePath).setTemplateAssetsUrl(clientApp.getTemplateAssetsUrl()).setEmailSubject(emailSubject).setTemplateModel(emailTemplateModel);
    sendEmail(emailRequest);
}
Also used : Serializable(java.io.Serializable) ClientApp(org.alfresco.repo.client.config.ClientAppConfig.ClientApp)

Example 5 with ClientApp

use of org.alfresco.repo.client.config.ClientAppConfig.ClientApp in project alfresco-repository by Alfresco.

the class QuickShareServiceImpl method sendEmailNotification.

@Override
public void sendEmailNotification(final QuickShareEmailRequest emailRequest) {
    ParameterCheck.mandatory("emailRequest", emailRequest);
    emailRequest.validate();
    ClientApp clientApp = clientAppConfig.getClient(emailRequest.getClient());
    if (clientApp == null) {
        throw new ClientAppNotFoundException("Client was not found [" + emailRequest.getClient() + "]");
    }
    // Set the details of the person sending the email
    final String authenticatedUser = AuthenticationUtil.getFullyAuthenticatedUser();
    final NodeRef senderNodeRef = personService.getPerson(authenticatedUser, false);
    final Map<QName, Serializable> senderProps = nodeService.getProperties(senderNodeRef);
    final String senderFirstName = (String) senderProps.get(ContentModel.PROP_FIRSTNAME);
    final String senderLastName = (String) senderProps.get(ContentModel.PROP_LASTNAME);
    final String senderFullName = ((senderFirstName != null ? senderFirstName + " " : "") + (senderLastName != null ? senderLastName : "")).trim();
    // Set the default model information
    Map<String, Serializable> templateModel = new HashMap<>(6);
    templateModel.put(FTL_SENDER_FIRST_NAME, senderFirstName);
    templateModel.put(FTL_SENDER_LAST_NAME, senderLastName);
    final String sharedNodeUrl = getUrl(clientApp.getProperty(CONFIG_SHARED_LINK_BASE_URL), CONFIG_SHARED_LINK_BASE_URL) + '/' + emailRequest.getSharedId();
    templateModel.put(FTL_SHARED_NODE_URL, sharedNodeUrl);
    templateModel.put(FTL_SHARED_NODE_NAME, emailRequest.getSharedNodeName());
    templateModel.put(FTL_SENDER_MESSAGE, emailRequest.getSenderMessage());
    final String templateAssetsUrl = getUrl(clientApp.getTemplateAssetsUrl(), ClientAppConfig.PROP_TEMPLATE_ASSETS_URL);
    templateModel.put(FTL_TEMPLATE_ASSETS_URL, templateAssetsUrl);
    // Set the email details
    Map<String, Serializable> actionParams = new HashMap<>();
    // Email sender. By default the current-user's email address will not be used to send this mail.
    // However, current-user's first and lastname will be used as the personal name.
    actionParams.put(MailActionExecuter.PARAM_FROM, this.defaultEmailSender);
    actionParams.put(MailActionExecuter.PARAM_FROM_PERSONAL_NAME, senderFullName);
    actionParams.put(MailActionExecuter.PARAM_SUBJECT, DEFAULT_EMAIL_SUBJECT);
    actionParams.put(MailActionExecuter.PARAM_SUBJECT_PARAMS, new Object[] { senderFirstName, senderLastName, emailRequest.getSharedNodeName() });
    actionParams.put(MailActionExecuter.PARAM_IGNORE_SEND_FAILURE, emailRequest.isIgnoreSendFailure());
    // Pick the template
    final String templatePath = emailHelper.getEmailTemplate(clientApp.getName(), getSharedLinkEmailTemplatePath(clientApp), EMAIL_TEMPLATE_REF);
    actionParams.put(MailActionExecuter.PARAM_TEMPLATE, templatePath);
    actionParams.put(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) templateModel);
    actionParams.put(MailActionExecuter.PARAM_LOCALE, getDefaultIfNull(emailHelper.getUserLocaleOrDefault(authenticatedUser), emailRequest.getLocale()));
    for (String to : emailRequest.getToEmails()) {
        Map<String, Serializable> params = new HashMap<>(actionParams);
        params.put(MailActionExecuter.PARAM_TO, to);
        Action mailAction = actionService.createAction(MailActionExecuter.NAME, params);
        actionService.executeAction(mailAction, null, false, true);
    }
}
Also used : ClientAppNotFoundException(org.alfresco.repo.client.config.ClientAppNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ScheduledPersistedAction(org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction) Action(org.alfresco.service.cmr.action.Action) QuickShareLinkExpiryAction(org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction) ClientApp(org.alfresco.repo.client.config.ClientAppConfig.ClientApp) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName)

Aggregations

ClientApp (org.alfresco.repo.client.config.ClientAppConfig.ClientApp)5 Serializable (java.io.Serializable)3 ClientAppNotFoundException (org.alfresco.repo.client.config.ClientAppNotFoundException)2 HashMap (java.util.HashMap)1 Action (org.alfresco.service.cmr.action.Action)1 ScheduledPersistedAction (org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction)1 QuickShareLinkExpiryAction (org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 QName (org.alfresco.service.namespace.QName)1 Test (org.junit.Test)1