Skip to content

Commit

Permalink
Merge pull request #193 from FOSSGIS-Hacking-Event-2013/3.4-improveme…
Browse files Browse the repository at this point in the history
…ntsGui

Improvements of the gui
  • Loading branch information
MrSnyder committed Dec 3, 2013
2 parents a3a0992 + 09c9a5c commit 9722826
Show file tree
Hide file tree
Showing 27 changed files with 382 additions and 146 deletions.
2 changes: 1 addition & 1 deletion deegree-client/deegree-jsf-console/pom.xml
Expand Up @@ -209,7 +209,7 @@
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.5</version>
<version>4.0</version>
</dependency>
</dependencies>
</project>
Expand Up @@ -27,36 +27,36 @@
----------------------------------------------------------------------------*/
package org.deegree.console;

import static javax.faces.application.FacesMessage.SEVERITY_ERROR;
import static org.deegree.console.JsfUtils.getWorkspace;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;

import org.apache.commons.io.IOUtils;
import org.deegree.console.metadata.ResourceManagerMetadata;
import org.deegree.console.metadata.ResourceProviderMetadata;
import org.deegree.services.controller.OGCFrontController;
import org.deegree.workspace.ResourceLocation;
import org.deegree.workspace.ResourceManager;
import org.deegree.workspace.ResourceMetadata;
import org.deegree.workspace.ResourceProvider;
import org.deegree.workspace.Workspace;
import org.deegree.workspace.standard.DefaultResourceIdentifier;
import org.deegree.workspace.standard.IncorporealResourceLocation;
import org.deegree.workspace.standard.DefaultResourceLocation;
import org.deegree.workspace.standard.DefaultWorkspace;

/**
* JSF backing bean for views of type "Create new XYZ resource".
*
* @author <a href="mailto:schneider@occamlabs.de">Markus Schneider</a>
*
* @since 3.3
* @since 3.4
*/
@ManagedBean
@ViewScoped
Expand All @@ -70,14 +70,19 @@ public abstract class AbstractCreateResourceBean {

private List<String> configTemplates;

private final transient ResourceManagerMetadata metadata;
private transient ResourceManagerMetadata metadata;

private Workspace workspace;
private File resourceDir;

public AbstractCreateResourceBean( Class<? extends ResourceManager<?>> resourceMgrClass ) {
workspace = OGCFrontController.getServiceWorkspace().getNewWorkspace();
ResourceManager<?> mgr = (ResourceManager<?>) workspace.getResourceManager( resourceMgrClass );
metadata = ResourceManagerMetadata.getMetadata( mgr, workspace );
protected AbstractCreateResourceBean() {
// required by JSF
}

protected AbstractCreateResourceBean( Class<? extends ResourceManager<?>> resourceMgrClass ) {
ResourceManager<?> mgr = getWorkspace().getResourceManager( resourceMgrClass );
metadata = ResourceManagerMetadata.getMetadata( mgr, getWorkspace() );
File wsDir = ( (DefaultWorkspace) getWorkspace() ).getLocation();
resourceDir = new File( wsDir, mgr.getMetadata().getWorkspacePath() );
if ( !getTypes().isEmpty() ) {
type = getTypes().get( 0 );
changeType( null );
Expand Down Expand Up @@ -132,16 +137,21 @@ public String create() {
try {
Class<?> pcls = metadata.getManager().getMetadata().getProviderClass();
DefaultResourceIdentifier<?> ident = new DefaultResourceIdentifier( pcls, id );
ResourceLocation<?> loc = new IncorporealResourceLocation( IOUtils.toByteArray( templateURL ), ident );
workspace.add( loc );
ResourceMetadata<?> rmd = workspace.getResourceMetadata( ident.getProvider(), ident.getId() );
if ( !resourceDir.mkdirs() ) {
throw new IOException( "Could not create resource directory '" + resourceDir + "'" );
}
File resourceFile = new File( resourceDir, id + ".xml" );
FileOutputStream os = new FileOutputStream( resourceFile );
IOUtils.copy( templateURL.openStream(), os );
os.close();
ResourceLocation<?> loc = new DefaultResourceLocation( resourceFile, ident );
getWorkspace().add( loc );
ResourceMetadata<?> rmd = getWorkspace().getResourceMetadata( ident.getProvider(), ident.getId() );
Config c = new Config( rmd, metadata.getManager(), getOutcome(), true );
c.setTemplate( templateURL );
return c.edit();
} catch ( Exception t ) {
t.printStackTrace();
FacesMessage fm = new FacesMessage( SEVERITY_ERROR, "Unable to create config: " + t.getMessage(), null );
FacesContext.getCurrentInstance().addMessage( null, fm );
JsfUtils.indicateException( "Creating resource", t );
}
return getOutcome();
}
Expand Down
Expand Up @@ -34,11 +34,13 @@
----------------------------------------------------------------------------*/
package org.deegree.console;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import org.deegree.console.datastore.feature.FeatureStoreConfig;
import org.deegree.console.metadata.ResourceManagerMetadata;
import org.deegree.console.metadata.ResourceProviderMetadata;
import org.deegree.services.controller.OGCFrontController;
Expand All @@ -55,7 +57,9 @@
*
* @version $Revision: $, $Date: $
*/
public abstract class AbstractResourceManagerBean<T extends ResourceManager<?>> {
public abstract class AbstractResourceManagerBean<T extends ResourceManager<?>> implements Serializable {

private static final long serialVersionUID = -7795125766411006135L;

private String newConfigType;

Expand All @@ -65,11 +69,15 @@ public abstract class AbstractResourceManagerBean<T extends ResourceManager<?>>

private String newConfigId;

protected final ResourceManager<?> resourceManager;
private transient ResourceManagerMetadata metadata;

protected transient ResourceManager<?> resourceManager;

private final ResourceManagerMetadata metadata;
private transient Workspace workspace;

private Workspace workspace;
protected AbstractResourceManagerBean() {
// default constructor required
}

protected AbstractResourceManagerBean( Class<T> mgrClass ) {
workspace = OGCFrontController.getServiceWorkspace().getNewWorkspace();
Expand Down Expand Up @@ -132,4 +140,15 @@ public String getStartView() {
return null;
}

public boolean getHasErrors() {
for ( ResourceMetadata<?> md : resourceManager.getResourceMetadata() ) {
FeatureStoreConfig config = new FeatureStoreConfig( md, resourceManager );
String state = config.getState();
if ( "Error".equals( state ) ) {
return true;
}
}
return false;
}

}
@@ -1,10 +1,12 @@
//$HeadURL$
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
This file is part of deegree
Copyright (C) 2001-2013 by:
- Department of Geography, University of Bonn -
and
- lat/lon GmbH -
and
- Occam Labs UG (haftungsbeschränkt) -
and others
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Expand All @@ -20,25 +22,17 @@
Contact information:
lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/
Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/
e-mail: info@deegree.org
----------------------------------------------------------------------------*/
website: http://www.deegree.org/
----------------------------------------------------------------------------*/
package org.deegree.console;

import static javax.faces.application.FacesMessage.SEVERITY_ERROR;
import static org.deegree.console.JsfUtils.getWorkspace;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -47,26 +41,24 @@
import javax.faces.context.FacesContext;

import org.apache.commons.io.IOUtils;
import org.deegree.services.controller.OGCFrontController;
import org.deegree.workspace.Resource;
import org.deegree.workspace.ResourceManager;
import org.deegree.workspace.ResourceMetadata;
import org.deegree.workspace.ResourceStates.ResourceState;
import org.deegree.workspace.Workspace;
import org.deegree.workspace.WorkspaceUtils;
import org.deegree.workspace.standard.AbstractResourceProvider;
import org.slf4j.Logger;

/**
* Wraps information on a {@link Resource} and its configuration file.
* JSF bean that wraps a {@link ResourceMetadata} and actions.
*
* @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
* @author <a href="mailto:schneider@occamlabs.de">Markus Schneider</a>
* @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
* @author last edited by: $Author$
*
* @version $Revision$, $Date$
* @since 3.4
*/
public class Config implements Comparable<Config> {
public class Config implements Comparable<Config>, Serializable {

private static final long serialVersionUID = -175529275940063759L;

private static final Logger LOG = getLogger( Config.class );

Expand All @@ -80,13 +72,14 @@ public class Config implements Comparable<Config> {

private String resourceOutcome;

private ResourceMetadata<?> metadata;
private transient ResourceMetadata<?> metadata;

protected Workspace workspace;
public Config() {
// constructor required by JSF
}

public Config( ResourceMetadata<?> metadata, ResourceManager<?> resourceManager, String resourceOutcome,
boolean autoActivate ) {
workspace = OGCFrontController.getServiceWorkspace().getNewWorkspace();
if ( metadata != null ) {
this.id = metadata.getIdentifier().getId();
}
Expand All @@ -107,9 +100,9 @@ public Config( ResourceMetadata<?> metadata, ResourceManager<?> resourceManager,

public void activate() {
try {
workspace.getLocationHandler().activate( metadata.getLocation() );
workspace.add( metadata.getLocation() );
WorkspaceUtils.reinitializeChain( workspace, metadata.getIdentifier() );
getWorkspace().getLocationHandler().activate( metadata.getLocation() );
getWorkspace().add( metadata.getLocation() );
WorkspaceUtils.reinitializeChain( getWorkspace(), metadata.getIdentifier() );
} catch ( Exception t ) {
t.printStackTrace();
FacesMessage fm = new FacesMessage( SEVERITY_ERROR, "Unable to activate resource: " + t.getMessage(), null );
Expand All @@ -120,12 +113,12 @@ public void activate() {

public void deactivate() {
try {
workspace.destroy( metadata.getIdentifier() );
workspace.getLocationHandler().deactivate( metadata.getLocation() );
getWorkspace().destroy( metadata.getIdentifier() );
getWorkspace().getLocationHandler().deactivate( metadata.getLocation() );
List<ResourceMetadata<?>> list = new ArrayList<ResourceMetadata<?>>();
WorkspaceUtils.collectDependents( list, workspace.getDependencyGraph().getNode( metadata.getIdentifier() ) );
WorkspaceUtils.collectDependents( list, getWorkspace().getDependencyGraph().getNode( metadata.getIdentifier() ) );
for ( ResourceMetadata<?> md : list ) {
workspace.getLocationHandler().deactivate( md.getLocation() );
getWorkspace().getLocationHandler().deactivate( md.getLocation() );
}
} catch ( Throwable t ) {
FacesMessage fm = new FacesMessage( SEVERITY_ERROR, "Unable to deactivate resource: " + t.getMessage(),
Expand All @@ -147,27 +140,28 @@ public String edit()

public void delete() {
try {
workspace.getLocationHandler().delete( metadata.getLocation() );
getWorkspace().getLocationHandler().delete( metadata.getLocation() );
} catch ( Throwable t ) {
FacesMessage fm = new FacesMessage( SEVERITY_ERROR, "Unable to deactivate resource: " + t.getMessage(),
null );
FacesContext.getCurrentInstance().addMessage( null, fm );
JsfUtils.indicateException( "Deleting resource file", t );
return;
}
try {
getWorkspace().destroy( metadata.getIdentifier() );
} catch ( Throwable t ) {
JsfUtils.indicateException( "Destroying resource", t );
}
}

public void showErrors() {
String msg = "Initialization of resource with id '" + id + "' failed:";

for ( String error : workspace.getErrorHandler().getErrors( metadata.getIdentifier() ) ) {
String msg = "Initialization of resource '" + id + "' failed: ";
for ( String error : getWorkspace().getErrorHandler().getErrors( metadata.getIdentifier() ) ) {
msg += error;
}

msg += " (The application server log may contain additional information.)";

FacesMessage fm = new FacesMessage( SEVERITY_ERROR, msg, null );
FacesContext.getCurrentInstance().addMessage( null, fm );
}

@Override
public int compareTo( Config o ) {
return id.compareTo( o.id );
}
Expand Down Expand Up @@ -213,7 +207,7 @@ public void setSchemaURL( URL schemaURL ) {
}

public String getState() {
ResourceState state = workspace.getStates().getState( metadata.getIdentifier() );
ResourceState state = getWorkspace().getStates().getState( metadata.getIdentifier() );
return state == null ? "Deactivated" : state.toString();
}

Expand Down

0 comments on commit 9722826

Please sign in to comment.