Search in sources :

Example 1 with TemplateUploadForm

use of eu.esdihumboldt.hale.server.templates.war.components.TemplateUploadForm in project hale by halestudio.

the class UploadTemplatePage method addControls.

@Override
protected void addControls(boolean loggedIn) {
    super.addControls(loggedIn);
    add(new TemplateUploadForm("upload", null));
}
Also used : TemplateUploadForm(eu.esdihumboldt.hale.server.templates.war.components.TemplateUploadForm)

Example 2 with TemplateUploadForm

use of eu.esdihumboldt.hale.server.templates.war.components.TemplateUploadForm in project hale by halestudio.

the class UpdateTemplatePage method addControls.

@Override
protected void addControls() {
    StringValue idParam = getPageParameters().get(0);
    if (!idParam.isNull() && !idParam.isEmpty()) {
        String templateId = idParam.toString();
        OrientGraph graph = DatabaseHelper.getGraph();
        try {
            Template template = null;
            try {
                template = Template.getByTemplateId(graph, templateId);
            } catch (NonUniqueResultException e) {
                log.error("Duplicate template representation: " + templateId, e);
            }
            if (template != null) {
                // get associated user
                Vertex v = template.getV();
                Iterator<Vertex> owners = v.getVertices(Direction.OUT, "owner").iterator();
                if (// user is admin
                UserUtil.isAdmin() || // or user is owner
                (owners.hasNext() && UserUtil.getLogin().equals(new User(owners.next(), graph).getLogin()))) {
                    // template name
                    add(new Label("name", template.getName()));
                    // upload form
                    add(new TemplateUploadForm("upload-form", templateId));
                } else {
                    throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_FORBIDDEN);
                }
            } else {
                throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Template not found.");
            }
        } finally {
            graph.shutdown();
        }
    } else
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST, "Template identifier must be specified.");
}
Also used : NonUniqueResultException(eu.esdihumboldt.util.blueprints.entities.NonUniqueResultException) Vertex(com.tinkerpop.blueprints.Vertex) User(eu.esdihumboldt.hale.server.model.User) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) TemplateUploadForm(eu.esdihumboldt.hale.server.templates.war.components.TemplateUploadForm) Label(org.apache.wicket.markup.html.basic.Label) AbortWithHttpErrorCodeException(org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException) StringValue(org.apache.wicket.util.string.StringValue) Template(eu.esdihumboldt.hale.server.model.Template)

Aggregations

TemplateUploadForm (eu.esdihumboldt.hale.server.templates.war.components.TemplateUploadForm)2 Vertex (com.tinkerpop.blueprints.Vertex)1 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)1 Template (eu.esdihumboldt.hale.server.model.Template)1 User (eu.esdihumboldt.hale.server.model.User)1 NonUniqueResultException (eu.esdihumboldt.util.blueprints.entities.NonUniqueResultException)1 Label (org.apache.wicket.markup.html.basic.Label)1 AbortWithHttpErrorCodeException (org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException)1 StringValue (org.apache.wicket.util.string.StringValue)1