Do automaticky odesílaných e-mailů lze nyní vložit URL na záznam

požadavku. Při otevření URL se nastaví kurzor v gridu na příslušný
záznam.
Verze_1.0
Josef Rokos 10 years ago
parent babb9f8312
commit a9a98cfd63

@ -0,0 +1,39 @@
package info.bukova.isspst;
import info.bukova.isspst.data.DataModel;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
public class CommonUrlResolver implements EntityUrlResolver {
@Autowired
private HttpServletRequest request;
protected String defaultUrl;
public CommonUrlResolver() {
}
@Override
public String entityUrl(Object entity) {
if (defaultUrl == null) {
this.defaultUrl = request.getRequestURL().toString();
this.defaultUrl = defaultUrl.substring(0, defaultUrl.indexOf(request.getServletPath()));
}
if (!DataModel.class.isAssignableFrom(entity.getClass())) {
return defaultUrl + "/app";
}
String url = Constants.URL_MAP.get(entity.getClass());
if (url == null) {
return defaultUrl + "/app";
}
return defaultUrl + url + "?select=" + String.valueOf(((DataModel)entity).getId());
}
}

@ -1,9 +1,15 @@
package info.bukova.isspst;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import info.bukova.isspst.data.Permission;
import info.bukova.isspst.data.PermissionType;
import info.bukova.isspst.data.Requirement;
import info.bukova.isspst.data.RequirementType;
import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.reporting.Report;
import info.bukova.isspst.reporting.ReportMapping;
import info.bukova.isspst.services.addressbook.AdbService;
@ -129,4 +135,10 @@ public class Constants {
public final static long REQ_TYPE_MATERIAL = 1;
public final static long REQ_TYPE_SERVICES = 2;
@SuppressWarnings("serial")
public final static Map<Class<?>, String> URL_MAP = Collections.unmodifiableMap(new HashMap<Class<?>, String>() {{
put(Requirement.class, "/main/orders/");
put(TripRequirement.class, "/main/trips/requirements/");
}} );
}

@ -0,0 +1,7 @@
package info.bukova.isspst;
public interface EntityUrlResolver {
public String entityUrl(Object entity);
}

@ -0,0 +1,39 @@
package info.bukova.isspst;
import info.bukova.isspst.data.Requirement;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
public class RequirementUrlResolver implements EntityUrlResolver {
private String defaultUrl;
@Autowired
private HttpServletRequest request;
public RequirementUrlResolver() {
}
@Override
public String entityUrl(Object entity) {
if (!(entity instanceof Requirement)) {
return defaultUrl + "/app";
}
if (defaultUrl == null) {
this.defaultUrl = request.getRequestURL().toString();
this.defaultUrl = defaultUrl.substring(0, defaultUrl.indexOf(request.getServletPath()));
}
Requirement req = (Requirement)entity;
if (req.getKind() == Constants.REQ_TYPE_MATERIAL) {
return defaultUrl + Constants.URL_MAP.get(req) + "material/?select=" + String.valueOf(req.getId());
} else {
return defaultUrl + Constants.URL_MAP.get(req) + "services/?select=" + String.valueOf(req.getId());
}
}
}

@ -0,0 +1,30 @@
package info.bukova.isspst;
import java.util.HashMap;
import java.util.Map;
public class UrlResolverHolder {
private EntityUrlResolver commonResolver;
private Map<Class<?>, EntityUrlResolver> resolvers;
public UrlResolverHolder(EntityUrlResolver common) {
this.commonResolver = common;
resolvers = new HashMap<Class<?>, EntityUrlResolver>();
}
public void setResolvers(Map<Class<?>, EntityUrlResolver> resolvers) {
this.resolvers = resolvers;
}
public EntityUrlResolver resolverFor(Class<?> clazz) {
EntityUrlResolver res = resolvers.get(clazz);
if (res == null) {
return commonResolver;
}
return res;
}
}

@ -1,5 +1,8 @@
package info.bukova.isspst.mail;
import info.bukova.isspst.EntityUrlResolver;
import info.bukova.isspst.UrlResolverHolder;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@ -12,6 +15,7 @@ public class EntityMessageBuilder implements MessageBuilder {
private final static Logger logger = LoggerFactory.getLogger(EntityMessageBuilder.class);
private boolean html;
private UrlResolverHolder urlResolverHolder;
public void setHtml(boolean html) {
this.html = html;
@ -53,7 +57,11 @@ public class EntityMessageBuilder implements MessageBuilder {
for (String p : properties) {
try {
if (p.equals("-url-")) {
ret = ret.replaceAll("\\[" + p + "\\]", getUrl(data));
} else {
ret = ret.replaceAll("\\[" + p + "\\]", BeanUtils.getProperty(data, p));
}
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
} catch (InvocationTargetException e) {
@ -68,4 +76,17 @@ public class EntityMessageBuilder implements MessageBuilder {
return ret;
}
private String getUrl(Object data) {
if (urlResolverHolder == null) {
return "";
}
EntityUrlResolver res = urlResolverHolder.resolverFor(data.getClass());
return res.entityUrl(data);
}
public void setUrlResolverHolder(UrlResolverHolder urlResolverHolder) {
this.urlResolverHolder = urlResolverHolder;
}
}

@ -43,6 +43,10 @@ public class MailerWithAttachement implements Mailer {
}
}
if (message.getReplyTo() == null) {
message.setReplyTo(message.getFrom());
}
helper.setFrom(message.getFrom());
helper.setReplyTo(message.getReplyTo());
helper.setTo(message.getTo());
@ -63,6 +67,7 @@ public class MailerWithAttachement implements Mailer {
}
try {
sender.send(mimeMessage);
logger.info("Mail queued for send");
} catch (MailAuthenticationException e) {
logger.error("Authentication error");
} catch (MailSendException e) {

@ -300,6 +300,7 @@ public class ListViewModel<T extends DataModel> extends DocumentViewModel
if (selIndex > -1) {
this.setDataBean(dataList.get(selIndex));
afterSelect();
}
}
@ -307,6 +308,10 @@ public class ListViewModel<T extends DataModel> extends DocumentViewModel
}
protected void afterSelect() {
}
@Command
@NotifyChange("dataBean")
public void onSort(@BindingParam("column") String column) {

@ -68,4 +68,9 @@ public class RequirementSubpage<T extends RequirementBase> extends ListViewModel
return false;
}
@Override
protected void afterSelect() {
BindUtils.postNotifyChange(null, null, this, "canApprove");
}
}

@ -94,6 +94,12 @@ public class GlobalSettingsVM {
message.setText(message.getText() + "[" + field + "]");
}
@Command
@NotifyChange("settings")
public void insertUrl(@BindingParam("message") MailMessage message) {
message.setText(message.getText() + "[-url-]");
}
@Command
@NotifyChange("settings")
public void addAddress() {

@ -30,6 +30,20 @@
<bean id="messageBuilder" class="info.bukova.isspst.mail.EntityMessageBuilder">
<property name="html" value="true"/>
<property name="urlResolverHolder" ref="urlResolverHolder"/>
</bean>
<bean id="commonUrlResolver" class="info.bukova.isspst.CommonUrlResolver"/>
<bean id="requirementUrlResolver" class="info.bukova.isspst.RequirementUrlResolver"/>
<bean id="urlResolverHolder" class="info.bukova.isspst.UrlResolverHolder">
<constructor-arg ref="commonUrlResolver"/>
<property name="resolvers">
<map>
<entry key="#{T(info.bukova.isspst.data.Requirement)}" value-ref="requirementUrlResolver"/>
</map>
</property>
</bean>
<!-- <bean id="mailer" class="info.bukova.rsfaktura.services.mail.ThreadMailer"> -->

@ -51,6 +51,6 @@
<div id="mainData">
<u:include src="${gridZul}" />
</div>
<div id="footer"> </div>
<div id="footer"> Verze 1.0 </div>
</div>
</html>

@ -21,7 +21,10 @@
<vbox>
<ckeditor toolbar="Basic" value="@bind(vm.settings.newReqTemplate.text)" width="460px" height="180px" if="${vm.canSave}"/>
<html content="@load(vm.settings.newReqTemplate.text)" width="460px" height="180px" if="${not vm.canSave}"/>
<hbox>
<button label="${labels.InsertField}" popup="fieldsNew, position=after_start" disabled="@load(not vm.canSave)"/>
<button label="${labels.GlobalSettingsInsertUrl}" onClick="@command('insertUrl', message=vm.settings.newReqTemplate)" disabled="@load(not vm.canSave)"/>
</hbox>
</vbox>
</row>
</rows>
@ -41,7 +44,10 @@
<vbox>
<ckeditor toolbar="Basic" value="@bind(vm.settings.authReqTemplate.text)" width="460px" height="180px" if="${vm.canSave}" />
<html content="@load(vm.settings.authReqTemplate.text)" width="460px" height="180px" if="${not vm.canSave}"/>
<hbox>
<button label="${labels.InsertField}" popup="fieldsAuth, position=after_start" disabled="@load(not vm.canSave)"/>
<button label="${labels.GlobalSettingsInsertUrl}" onClick="@command('insertUrl', message=vm.settings.authReqTemplate)" disabled="@load(not vm.canSave)"/>
</hbox>
</vbox>
</row>
</rows>

Loading…
Cancel
Save