annotate read-write-mode

This commit is contained in:
Peter Hormanns 2012-07-27 10:54:11 +00:00
parent bb34a9f5ee
commit d596fcbf58
13 changed files with 74 additions and 126 deletions

View File

@ -28,3 +28,14 @@ ALTER TABLE ONLY domain__domain_option
ALTER TABLE ONLY domain__domain_option
ADD CONSTRAINT domain_id_fkey FOREIGN KEY (domain_id)
REFERENCES domain(domain_id) DEFERRABLE;
update domain set domain_since=domain_filed;
alter table domain drop column domain_free;
alter table domain drop column domain_until;
alter table domain drop column domain_filed;
alter table domain drop column domain_reminder;
alter table domain drop column domain_template;

View File

@ -7,6 +7,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface AnnFieldValidation {
String value();
public @interface AnnFieldIO {
String validation() default "[A-Za-z0-9\\_\\-]";
ReadWriteAccess rw() default ReadWriteAccess.WRITEONCE;
}

View File

@ -81,14 +81,14 @@ public class GenericModuleImpl implements ModuleInterface {
private void validateAllFields(Class<?> clasz, AbstractEntity anEntity)
throws HSAdminException {
for (Field f : clasz.getDeclaredFields()) {
AnnFieldValidation fieldValidation = f.getAnnotation(AnnFieldValidation.class);
AnnFieldIO fieldValidation = f.getAnnotation(AnnFieldIO.class);
if (fieldValidation != null) {
try {
Method method = clasz.getMethod(getterName(f));
Object valueObject = method.invoke(anEntity);
if (valueObject instanceof String) {
if (!Pattern.matches(fieldValidation.value(), (String) valueObject)) {
throw new HSAdminException("validation of field " + f.getName() + " failed, pattern: " + fieldValidation.value());
if (!Pattern.matches(fieldValidation.validation(), (String) valueObject)) {
throw new HSAdminException("validation of field " + f.getName() + " failed, pattern: " + fieldValidation.validation());
}
}
} catch (Exception e) {

View File

@ -0,0 +1,7 @@
package de.hsadmin.core.model;
public enum ReadWriteAccess {
READONLY, READWRITE, WRITEONLY, WRITEONCE;
}

View File

@ -23,7 +23,8 @@ import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.core.model.SearchFilter;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
@ -43,23 +44,24 @@ public abstract class Database extends AbstractEntity implements Serializable {
@Column(name = "database_id", columnDefinition = "integer", updatable=false, insertable=false)
private long id;
@AnnFieldValidation("[a-zA-Z]*")
@AnnFieldIO(validation="[a-zA-Z]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "engine", columnDefinition = "character varying(12)", updatable=false)
private String instance;
@AnnFieldValidation("[a-z0-9\\_]*")
@AnnFieldIO(validation="[a-z0-9\\_]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "name", columnDefinition = "character varying(24)", updatable=false)
private String name;
@AnnFieldValidation("[a-z0-9\\_]*")
@AnnFieldIO(validation="[a-z0-9\\_]*", rw=ReadWriteAccess.READWRITE)
@Column(name = "owner", columnDefinition = "character varying(24)")
private String owner;
@JoinColumn(name = "packet_id", columnDefinition = "integer", updatable=false)
@ManyToOne(fetch = EAGER)
@AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.WRITEONCE)
private Pac pac;
@AnnFieldValidation("[A-Za-z0-9\\_\\-]*")
@AnnFieldIO(validation="[A-Za-z0-9\\_\\-]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "encoding", columnDefinition = "character varying(24)", updatable=false)
private String encoding;

View File

@ -24,7 +24,8 @@ import javax.persistence.Transient;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
@ -42,20 +43,21 @@ public abstract class DatabaseUser extends AbstractEntity implements Serializabl
@Column(name = "dbuser_id", columnDefinition = "integer", updatable=false, insertable=false)
private long id;
@AnnFieldValidation("[a-z0-9\\_]*")
@AnnFieldIO(validation="[a-z0-9\\_]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "name", columnDefinition = "character varying(24)", updatable=false)
private String name;
@AnnFieldValidation("[^']*")
@AnnFieldIO(validation="[^']*", rw=ReadWriteAccess.WRITEONLY)
@Transient
private String password;
@AnnFieldValidation("[a-zA-Z]*")
@AnnFieldIO(validation="[a-zA-Z]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "engine", columnDefinition = "character varying(12)", updatable=false)
protected String instance;
@JoinColumn(name = "packet_id", columnDefinition = "integer", updatable=false)
@ManyToOne(fetch = EAGER)
@AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.WRITEONCE)
protected Pac pac;
protected DatabaseUser() {

View File

@ -22,8 +22,9 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.AnnModuleImpl;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.mods.user.UnixUser;
@Entity(name = "Domains")
@ -37,38 +38,25 @@ public class Domain extends AbstractEntity {
@GeneratedValue(strategy = SEQUENCE, generator = "DomainsSeqGen")
private long id;
@AnnFieldValidation("([-a-z0-9]+\\.)+[a-z]{2,}")
@AnnFieldIO(validation="([-a-z0-9]+\\.)+[a-z]{2,}", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "domain_name", columnDefinition = "character varying(256)", nullable = false)
private String name;
@AnnFieldIO(rw=ReadWriteAccess.WRITEONCE)
@JoinColumn(name = "domain_owner", columnDefinition = "integer", nullable = false)
@ManyToOne(fetch = EAGER)
private UnixUser user;
@AnnFieldValidation("[a-z]*")
@Column(name = "domain_status", columnDefinition = "character varying(12)", nullable = false)
private String status;
@Column(name = "domain_status_changed", columnDefinition = "date", nullable = false)
@Temporal(javax.persistence.TemporalType.DATE)
private Date statusChanged;
@Column(name = "domain_filed", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date filed;
@AnnFieldIO(validation="[0-9\\.\\/\\-]*", rw=ReadWriteAccess.READONLY)
@Column(name = "domain_since", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date since;
@Column(name = "domain_until", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date until;
@AnnFieldValidation("[a-z0-9\\-\\.]*")
@AnnFieldIO(validation="[a-z0-9\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "domain_dns_master", columnDefinition = "character varying(64)")
private String dnsMaster;
@AnnFieldIO(validation="[a-zA-Z0-9\\-\\.]*", rw=ReadWriteAccess.READWRITE)
@ManyToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
@JoinTable(name="domain__domain_option",
joinColumns={@JoinColumn(name="domain_id", referencedColumnName="domain_id")},
@ -81,8 +69,6 @@ public class Domain extends AbstractEntity {
public Domain(String name, UnixUser user) {
this.name = name;
this.user = user;
this.statusChanged = new java.util.Date();
this.status = Status.FILED.toString();
}
public static String createQueryFromStringKey(String humanKey) {
@ -123,30 +109,6 @@ public class Domain extends AbstractEntity {
this.user = user;
}
public Status getStatus() {
return Status.valueFor(status);
}
public void setStatus(Status status) {
this.status = status.toString();
}
public Date getStatusChanged() {
return statusChanged;
}
public void setStatusChanged(Date statusChanged) {
this.statusChanged = statusChanged;
}
public Date getFiled() {
return filed;
}
public void setFiled(Date filed) {
this.filed = filed;
}
public Date getSince() {
return since;
}
@ -155,14 +117,6 @@ public class Domain extends AbstractEntity {
this.since = since;
}
public Date getUntil() {
return until;
}
public void setUntil(Date until) {
this.until = until;
}
public String getDnsMaster() {
return dnsMaster;
}
@ -226,40 +180,4 @@ public class Domain extends AbstractEntity {
this.domainOptions = domainOptions;
}
public static enum Status {
NONE(""),
ERROR("error"),
FILED("filed"),
SELF("self"),
REGISTERING("registering"),
REGISTERED("registered"),
TRANSFERRING("transferring"),
NACK_RECEIVED("KK-NACK"),
ACK_RECEIVED("KK-ACK"),
MANAGED("connected"),
LEAVE_SIGNALLED("KK-sig"),
LEAVING("leaving"),
GONE("gone"),
CLOSE_REQUESTED("CLO-req"),
CLOSING("closing"),
CLOSED("closed");
private Status(String aValue) {
this.aValue = aValue;
}
public String toString() {
return aValue;
}
private String aValue;
public static Status valueFor(String str) {
for (Status val : Status.values())
if (val.toString().equals(str))
return val;
return null;
}
}
}

View File

@ -12,7 +12,6 @@ import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.mods.dom.Domain.Status;
import de.hsadmin.mods.email.EMailAddress;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
@ -81,9 +80,7 @@ public class DomainModuleImpl extends AbstractModuleImpl {
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
Domain dom = (Domain) newEntity;
Date now = new Date();
dom.setFiled(now);
dom.setStatus(Status.SELF);
dom.setStatusChanged(now);
dom.setSince(now);
dom.setDnsMaster("dns.hostsharing.net");
if (dom.getName() == null || dom.getName().length() == 0) {
throw new HSAdminException("domain name required");

View File

@ -15,7 +15,8 @@ import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.mods.user.UnixUser;
@Table(name="domain_option")
@ -28,7 +29,7 @@ public class DomainOption extends AbstractEntity {
@GeneratedValue(strategy = SEQUENCE, generator = "DomainOptionSeqGen")
private long id;
@AnnFieldValidation("[a-z0-9]+")
@AnnFieldIO(validation="[a-z0-9]+", rw=ReadWriteAccess.READONLY)
@Column(name = "domain_option_name", columnDefinition = "character varying(256)", nullable = false)
private String name;

View File

@ -17,9 +17,10 @@ import javax.persistence.Table;
import javax.persistence.Transient;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.AnnModuleImpl;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.core.model.SearchFilter;
import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.user.UnixUser;
@ -43,19 +44,20 @@ public class EMailAddress extends AbstractEntity implements Serializable {
@Column(name = "emailaddr_id", columnDefinition = "integer")
private long id;
@AnnFieldValidation("[A-Za-z0-9\\_\\-\\.\\+]*")
@AnnFieldIO(validation="[A-Za-z0-9\\_\\-\\.\\+]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "localpart", updatable = false, nullable= false)
private String localpart = "";
@AnnFieldValidation("[a-z0-9\\-\\.]*")
@AnnFieldIO(validation="[a-z0-9\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "subdomain")
private String subdomain;
@AnnFieldIO(validation="[a-z0-9\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
@ManyToOne(fetch = EAGER)
@JoinColumn(name = "domain_id", columnDefinition = "integer", updatable = false)
private Domain domain;
@AnnFieldValidation("[\\x20-\\x7E]*")
@AnnFieldIO(validation="[\\x20-\\x7E]*", rw=ReadWriteAccess.READWRITE)
@Column(name = "target", nullable= false)
private String target;

View File

@ -18,8 +18,9 @@ import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.AnnModuleImpl;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.core.model.SearchFilter;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
@ -44,13 +45,14 @@ public class EMailAlias extends AbstractEntity implements Serializable {
@ManyToOne()
@JoinColumn(name = "pac_id", columnDefinition = "integer")
@AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.WRITEONCE)
private Pac pac;
@AnnFieldValidation("[a-z0-9\\_\\-\\.\\+]*")
@AnnFieldIO(validation="[a-z0-9\\_\\-\\.\\+]*", rw=ReadWriteAccess.WRITEONCE)
@Column(updatable=false)
private String name;
@AnnFieldValidation("[\\x20-\\x7E]*")
@AnnFieldIO(validation="[\\x20-\\x7E]*", rw=ReadWriteAccess.READWRITE)
@Column
private String target;

View File

@ -17,8 +17,9 @@ import javax.persistence.Table;
import javax.persistence.Transient;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AnnFieldValidation;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.AnnModuleImpl;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.core.util.Config;
import de.hsadmin.mods.pac.Pac;
@ -39,36 +40,40 @@ public class UnixUser extends AbstractEntity implements Serializable {
@Column(name="userid", columnDefinition="integer", nullable=false, updatable=false)
private long userId;
@AnnFieldValidation("[a-z0-9\\_\\-\\.]*")
@AnnFieldIO(validation="[a-z0-9\\_\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name="name", columnDefinition = "character varying(24)", unique=true, updatable=false)
private String name;
@AnnFieldValidation("[^:]*")
@AnnFieldIO(validation="[^:]*", rw=ReadWriteAccess.WRITEONLY)
@Transient
private String password;
@AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.WRITEONCE)
@JoinColumn(name = "packet_id", columnDefinition = "integer", updatable=false)
@ManyToOne(fetch = EAGER)
private Pac pac;
@AnnFieldValidation("[a-zA-Z0-9\\_\\-\\.\\,\\ ]*")
@AnnFieldIO(validation="[a-zA-Z0-9\\_\\-\\.\\,\\ ]*", rw=ReadWriteAccess.READWRITE)
@Column(name = "comment", columnDefinition = "character varying(128)")
private String comment;
@AnnFieldValidation("[a-z\\/]*")
@AnnFieldIO(validation="[a-z\\/]*", rw=ReadWriteAccess.READWRITE)
@Column(name = "shell", columnDefinition = "character varying(32)")
private String shell;
@AnnFieldValidation("[a-z0-9\\/\\_\\-\\.]*")
@AnnFieldIO(validation="[a-z0-9\\/\\_\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
@Column(name = "homedir", columnDefinition = "character varying(48)", updatable=false)
private String homedir;
@AnnFieldIO(rw=ReadWriteAccess.READWRITE)
@Column(name = "locked", columnDefinition = "boolean")
private boolean locked;
@AnnFieldIO(validation="[0-9]*", rw=ReadWriteAccess.READWRITE)
@Column(name = "quota_softlimit", columnDefinition = "integer")
private Integer quotaSoftlimit;
@AnnFieldIO(validation="[0-9]*", rw=ReadWriteAccess.READWRITE)
@Column(name = "quota_hardlimit", columnDefinition = "integer")
private Integer quotaHardlimit;

View File

@ -36,7 +36,7 @@ public class DomainRemote extends AbstractRemote {
resultMap.put("hive", hive);
String pac = dom.getUser().getPac().getName();
resultMap.put("pac", pac);
Date sDate = dom.getFiled();
Date sDate = dom.getSince();
if (assertNotNull(sDate)) {
String since = df.format(sDate);
resultMap.put("since", since);