implement pac update

This commit is contained in:
Peter Hormanns 2012-09-21 14:16:22 +02:00
parent 1dd78a708d
commit da5f5cd6fb
6 changed files with 77 additions and 30 deletions

View File

@ -39,7 +39,7 @@
<target name="deploy" depends="war"> <target name="deploy" depends="war">
<delete dir="${hsar.deploy.dir}/hsar" /> <delete dir="${hsar.deploy.dir}/hsar" />
<copy file="build/hsar.war" todir="${hsar.deploy.dir}" /> <copy file="build/hsar.war" todir="${hsar.deploy.dir}" />
<sleep minutes="2"/> <!-- <sleep minutes="2"/> -->
</target> </target>
<target name="jar" depends="enhance"> <target name="jar" depends="enhance">

View File

@ -27,8 +27,13 @@ import de.hsadmin.mods.user.UnixUser;
public class DomainProcessorFactory implements EntityProcessorFactory { public class DomainProcessorFactory implements EntityProcessorFactory {
private static final String[] DW_STRUCTURE = new String[] { "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "cgi", "fastcgi", "cgi-ssl", "fastcgi-ssl", "etc", "var" }; private static final String[] DW_STRUCTURE = new String[] {
private static final String[] SW_STRUCTURE = new String[] { "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "etc", "var" }; "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "cgi", "fastcgi", "cgi-ssl", "fastcgi-ssl", "etc", "var"
};
private static final String[] SW_STRUCTURE = new String[] {
"htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "etc", "var"
};
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) throws ProcessorException { public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) throws ProcessorException {
String hiveName = entity.getHiveName(); String hiveName = entity.getHiveName();

View File

@ -75,7 +75,7 @@ public class Pac extends AbstractEntity implements Serializable {
@ManyToOne(fetch = EAGER) @ManyToOne(fetch = EAGER)
private INetAddress oldINetAddr; private INetAddress oldINetAddr;
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac") @OneToMany(fetch = EAGER, cascade = ALL, mappedBy="pac")
private Set<PacComponent> pacComponents; private Set<PacComponent> pacComponents;
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac") @OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac")

View File

@ -110,9 +110,16 @@ public class PacModuleImpl extends AbstractModuleImpl {
} }
@Override @Override
public AbstractEntity update(AbstractEntity existingEntity) public AbstractEntity update(AbstractEntity entity)
throws HSAdminException { throws HSAdminException {
throw new AuthorisationException(getTransaction().getLoginUser(), "update", existingEntity); UnixUser loginUser = getTransaction().getLoginUser();
if (entity instanceof Pac) {
Pac pac = (Pac) entity;
} else {
throw new AuthorisationException(loginUser, "update", entity);
}
needsWriteAccessOn(entity, "update");
return super.update(entity);
} }
@Override @Override
@ -154,4 +161,19 @@ public class PacModuleImpl extends AbstractModuleImpl {
super.delete(existingEntity); super.delete(existingEntity);
} }
private void needsWriteAccessOn(AbstractEntity entity, String method) throws AuthorisationException {
UnixUser loginUser = getTransaction().getLoginUser();
if (entity instanceof Pac) {
Pac pac = (Pac) entity;
String aLoginUserName = loginUser.getName();
boolean isPacAdmin = loginUser.hasPacAdminRoleFor(pac);
boolean isCustomer = aLoginUserName.equals(pac.getCustomer().getName());
boolean isHostmaster = loginUser.hasHostmasterRole();
if (!isPacAdmin && !isCustomer && !isHostmaster) {
throw new AuthorisationException(loginUser, method, pac);
}
} else {
throw new AuthorisationException(loginUser, method, entity);
}
}
} }

View File

@ -275,7 +275,7 @@ public class UnixUser extends AbstractEntity implements Serializable {
return getName().equals(cust.getName()) || hasHostmasterRole(); return getName().equals(cust.getName()) || hasHostmasterRole();
} }
public boolean hasPacAdminRoleFor(de.hsadmin.mods.pac.Pac pac) { public boolean hasPacAdminRoleFor(Pac pac) {
return pac != null && return pac != null &&
(pac.getName().equals(getName()) (pac.getName().equals(getName())
|| hasCustomerRoleFor(pac.getCustomer()) ); || hasCustomerRoleFor(pac.getCustomer()) );

View File

@ -1,10 +1,9 @@
package de.hsadmin.remote; package de.hsadmin.remote;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.SortedSet; import java.util.Set;
import java.util.TreeSet;
import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.util.TextUtil; import de.hsadmin.core.util.TextUtil;
@ -27,27 +26,38 @@ public class PacRemote extends AbstractRemote {
resultMap.put("curinetaddr", pac.getCurINetAddr().getInetAddr()); resultMap.put("curinetaddr", pac.getCurINetAddr().getInetAddr());
resultMap.put("created", TextUtil.format(pac.getCreated())); resultMap.put("created", TextUtil.format(pac.getCreated()));
resultMap.put("basepac", pac.getBasepac().getName()); resultMap.put("basepac", pac.getBasepac().getName());
SortedSet<PacComponent> sortedComponents = new TreeSet<PacComponent>(new Comparator<PacComponent>() {
@Override Map<String, Object> components = new HashMap<String, Object>();
public int compare(PacComponent o1, PacComponent o2) { Set<PacComponent> pacComponents = pac.getPacComponents();
return o2.getBaseComponent().getSorting() - o1.getBaseComponent().getSorting(); for (PacComponent comp : pacComponents) {
} int quantity = comp.getQuantity();
}); if (quantity > 0) {
sortedComponents.addAll(pac.getPacComponents()); components.put(comp.getBaseComponent().getFeature(), Integer.toString(quantity));
StringBuffer bf = new StringBuffer();
boolean empty = true;
for (PacComponent comp : sortedComponents) {
if (comp.getQuantity() > 0) {
if (!empty) {
bf.append("; ");
}
bf.append(comp.getBaseComponent().getFeature());
bf.append("=");
bf.append(comp.getQuantity());
empty = false;
} }
} }
resultMap.put("components", bf.toString()); resultMap.put("components", components);
// SortedSet<PacComponent> sortedComponents = new TreeSet<PacComponent>(new Comparator<PacComponent>() {
// @Override
// public int compare(PacComponent o1, PacComponent o2) {
// return o2.getBaseComponent().getSorting() - o1.getBaseComponent().getSorting();
// }
// });
// sortedComponents.addAll(pac.getPacComponents());
// StringBuffer bf = new StringBuffer();
// boolean empty = true;
// for (PacComponent comp : sortedComponents) {
// if (comp.getQuantity() > 0) {
// if (!empty) {
// bf.append("; ");
// }
// bf.append(comp.getBaseComponent().getFeature());
// bf.append("=");
// bf.append(comp.getQuantity());
// empty = false;
// }
// }
// resultMap.put("components", bf.toString());
} }
@Override @Override
@ -86,7 +96,17 @@ public class PacRemote extends AbstractRemote {
hive.setName(hiveName); hive.setName(hiveName);
pac.setHive(hive); pac.setHive(hive);
} }
pac.setName((String) setParams.get("name")); Object componentsObj = setParams.get("components");
if (componentsObj != null && componentsObj instanceof Map) {
Map<?, ?> componentsMap = (Map<?, ?>) componentsObj;
for (Object key : componentsMap.keySet()) {
pac.getPacComponent(key.toString()).setQuantity(Integer.parseInt(componentsMap.get(key).toString()));
}
}
Object nameParamObj = setParams.get("name");
if (nameParamObj != null && nameParamObj instanceof String) {
pac.setName((String) nameParamObj);
}
} }
@Override @Override