org.sakaiproject.metaobj.shared.mgt.impl
Class StructuredArtifactDefinitionManagerImpl

java.lang.Object
  extended byorg.springframework.dao.support.DaoSupport
      extended byorg.springframework.orm.hibernate.support.HibernateDaoSupport
          extended byorg.sakaiproject.metaobj.shared.mgt.impl.StructuredArtifactDefinitionManagerImpl
All Implemented Interfaces:
DownloadableManager, DuplicatableToolService, InitializingBean, StructuredArtifactDefinitionManager

public class StructuredArtifactDefinitionManagerImpl
extends HibernateDaoSupport
implements StructuredArtifactDefinitionManager, DuplicatableToolService, DownloadableManager

Author:
chmaurer, jbush

Field Summary
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Fields inherited from interface org.sakaiproject.metaobj.shared.mgt.StructuredArtifactDefinitionManager
GLOBAL_SAD_QUALIFIER
 
Constructor Summary
StructuredArtifactDefinitionManagerImpl()
           
 
Method Summary
protected  String calculateSchemaHash(StructuredArtifactDefinitionBean bean)
           
 StructuredArtifactHomeInterface convertToHome(StructuredArtifactDefinitionBean sad)
           
 org.jdom.Element createFormViewXml(String formId, String returnUrl)
           
 org.jdom.Document exportSADAsXML(StructuredArtifactDefinitionBean bean)
          Given a bean this method will convert it into a new XML document.
protected  StructuredArtifactDefinitionBean findBean(StructuredArtifactDefinitionBean bean)
           
 List findGlobalHomes()
           
 List findHomes()
           
 List findHomes(Id currentWorksiteId)
           
 ArtifactFinder getArtifactFinder()
           
 ArtifactFinderManager getArtifactFinderManager()
           
 AuthenticationManager getAuthManager()
           
 AuthorizationFacade getAuthzManager()
           
 ContentHostingService getContentHosting()
           
protected  Site getCurrentSite()
           
 List getGlobalSites()
           
 List getGlobalSiteTypes()
           
 Map getHomes()
           
 IdManager getIdManager()
           
 Collection getRootElements(StructuredArtifactDefinitionBean sad)
           
protected  org.jdom.Element getStructuredArtifactRootElement(StructuredArtifactDefinition sad, StructuredArtifact artifact)
           
protected  Id getToolId()
           
 ToolManager getToolManager()
           
 Map getWorksiteHomes(Id worksiteId)
           
 WorksiteManager getWorksiteManager()
           
 void importResources(ToolConfiguration fromTool, ToolConfiguration toTool, List resourceIds)
           
 StructuredArtifactDefinitionBean importSad(Id worksiteId, InputStream in, boolean findExisting, boolean publish)
           
 StructuredArtifactDefinitionBean importSad(Id worksiteId, InputStream in, boolean findExisting, boolean publish, boolean foundThrowsException)
           
 boolean importSADResource(Id worksiteId, String resourceId, boolean findExisting)
          Given a resource id, this parses out the Form from its input stream.
protected  void init()
           
 boolean isGlobal()
           
protected  boolean isGlobal(String siteId)
           
 StructuredArtifactDefinitionBean loadHome(Id id)
           
 StructuredArtifactDefinitionBean loadHome(String type)
           
 StructuredArtifactDefinitionBean loadHomeByExternalType(String externalType, Id worksiteId)
           
protected  SchemaNode loadNode(StructuredArtifactDefinitionBean sad)
           
 void packageForDownload(Map params, OutputStream out)
           
 void packageFormForExport(String formId, OutputStream os)
          This is the default method for exporting a form into a stream.
 void packageFormForExport(String formId, OutputStream os, boolean checkPermission)
          This method will export a form into a stream.
 StructuredArtifactDefinitionBean readSADfromZip(ZipInputStream zis, String worksite, boolean publish)
           
protected  boolean sadExists(StructuredArtifactDefinitionBean sad)
           
 StructuredArtifactDefinitionBean save(StructuredArtifactDefinitionBean bean)
           
protected  void saveAll(StructuredArtifactDefinition sad, Collection artifacts)
           
 void setArtifactFinder(ArtifactFinder artifactFinder)
           
 void setArtifactFinderManager(ArtifactFinderManager artifactFinderManager)
           
 void setAuthzManager(AuthorizationFacade authzManager)
           
 void setContentHosting(ContentHostingService contentHosting)
           
 void setGlobalSites(List globalSites)
           
 void setGlobalSiteTypes(List globalSiteTypes)
           
 void setIdManager(IdManager idManager)
           
 void setToolManager(ToolManager toolManager)
           
 void setWorksiteManager(WorksiteManager worksiteManager)
           
protected  void transform(StructuredArtifactDefinition sad, StructuredArtifact artifact)
           
protected  void updateExistingArtifacts(StructuredArtifactDefinition sad)
          Uses the submitted xsl file to transform the existing artifacts into the schema.
protected  void updateSchemaHash()
           
protected  void validateAfterTransform(StructuredArtifactDefinition sad, StructuredArtifact artifact)
           
 void validateSchema(StructuredArtifactDefinitionBean sad)
           
 void writeSADasXMLtoStream(StructuredArtifactDefinitionBean bean, OutputStream os)
          Given a bean, this method puts it into a stream via UTF-8 encoding
 void writeSADtoZip(StructuredArtifactDefinitionBean bean, ZipOutputStream zos)
           
 void writeSADtoZip(StructuredArtifactDefinitionBean bean, ZipOutputStream zos, String path)
           
 
Methods inherited from class org.springframework.orm.hibernate.support.HibernateDaoSupport
checkDaoConfig, closeSessionIfNecessary, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StructuredArtifactDefinitionManagerImpl

public StructuredArtifactDefinitionManagerImpl()
Method Detail

getHomes

public Map getHomes()
Specified by:
getHomes in interface StructuredArtifactDefinitionManager

getWorksiteHomes

public Map getWorksiteHomes(Id worksiteId)
Specified by:
getWorksiteHomes in interface StructuredArtifactDefinitionManager
Parameters:
worksiteId -
Returns:
a map with all worksite and global homes

findHomes

public List findHomes()
Specified by:
findHomes in interface StructuredArtifactDefinitionManager
Returns:
list of published sads or sads owned by current user

findGlobalHomes

public List findGlobalHomes()
Specified by:
findGlobalHomes in interface StructuredArtifactDefinitionManager
Returns:
list of all published globals or global sad owned by current user or waiting for approval

findHomes

public List findHomes(Id currentWorksiteId)
Specified by:
findHomes in interface StructuredArtifactDefinitionManager
Parameters:
currentWorksiteId -
Returns:
list of globally published sads or published sad in currentWorksiteId or sads in currentWorksiteId owned by current user

loadHome

public StructuredArtifactDefinitionBean loadHome(String type)
Specified by:
loadHome in interface StructuredArtifactDefinitionManager

loadHome

public StructuredArtifactDefinitionBean loadHome(Id id)
Specified by:
loadHome in interface StructuredArtifactDefinitionManager

loadHomeByExternalType

public StructuredArtifactDefinitionBean loadHomeByExternalType(String externalType,
                                                               Id worksiteId)
Specified by:
loadHomeByExternalType in interface StructuredArtifactDefinitionManager

save

public StructuredArtifactDefinitionBean save(StructuredArtifactDefinitionBean bean)
Specified by:
save in interface StructuredArtifactDefinitionManager

getIdManager

public IdManager getIdManager()
Returns:
Returns the idManager.

setIdManager

public void setIdManager(IdManager idManager)
Parameters:
idManager - The idManager to set.

isGlobal

public boolean isGlobal()
Specified by:
isGlobal in interface StructuredArtifactDefinitionManager
Returns:
true if user is in a SAD tool that is configured to manipulate globals SADs

isGlobal

protected boolean isGlobal(String siteId)

getCurrentSite

protected Site getCurrentSite()

getRootElements

public Collection getRootElements(StructuredArtifactDefinitionBean sad)
Specified by:
getRootElements in interface StructuredArtifactDefinitionManager

validateSchema

public void validateSchema(StructuredArtifactDefinitionBean sad)
Specified by:
validateSchema in interface StructuredArtifactDefinitionManager

convertToHome

public StructuredArtifactHomeInterface convertToHome(StructuredArtifactDefinitionBean sad)
Specified by:
convertToHome in interface StructuredArtifactDefinitionManager

loadNode

protected SchemaNode loadNode(StructuredArtifactDefinitionBean sad)
                       throws TypeException,
                              IdUnusedException,
                              PermissionException,
                              ServerOverloadException
Throws:
TypeException
IdUnusedException
PermissionException
ServerOverloadException

sadExists

protected boolean sadExists(StructuredArtifactDefinitionBean sad)
                     throws PersistenceException
Throws:
PersistenceException

validateAfterTransform

protected void validateAfterTransform(StructuredArtifactDefinition sad,
                                      StructuredArtifact artifact)
                               throws OspException
Parameters:
sad -
artifact -
Throws:
OspException - if artifact doesn't validate

saveAll

protected void saveAll(StructuredArtifactDefinition sad,
                       Collection artifacts)

updateExistingArtifacts

protected void updateExistingArtifacts(StructuredArtifactDefinition sad)
                                throws OspException
Uses the submitted xsl file to transform the existing artifacts into the schema. This process puts the artifact home into system only start while is does its work. This is necessary so that users won't be able to update artifacts while this is going on. The system transforms every object in memory and validates before writing any artifact back out. This way if something fails the existing data will stay intact.

TODO possible memory issues TODO all this work need to be atomic

Parameters:
sad -
Throws:
OspException

getStructuredArtifactRootElement

protected org.jdom.Element getStructuredArtifactRootElement(StructuredArtifactDefinition sad,
                                                            StructuredArtifact artifact)

transform

protected void transform(StructuredArtifactDefinition sad,
                         StructuredArtifact artifact)
                  throws IOException,
                         TransformerException,
                         org.jdom.JDOMException
Throws:
IOException
TransformerException
org.jdom.JDOMException

getAuthManager

public AuthenticationManager getAuthManager()

getArtifactFinderManager

public ArtifactFinderManager getArtifactFinderManager()

setArtifactFinderManager

public void setArtifactFinderManager(ArtifactFinderManager artifactFinderManager)

getAuthzManager

public AuthorizationFacade getAuthzManager()

setAuthzManager

public void setAuthzManager(AuthorizationFacade authzManager)

getWorksiteManager

public WorksiteManager getWorksiteManager()

setWorksiteManager

public void setWorksiteManager(WorksiteManager worksiteManager)

getToolManager

public ToolManager getToolManager()

setToolManager

public void setToolManager(ToolManager toolManager)

getToolId

protected Id getToolId()

importResources

public void importResources(ToolConfiguration fromTool,
                            ToolConfiguration toTool,
                            List resourceIds)
Specified by:
importResources in interface DuplicatableToolService

getContentHosting

public ContentHostingService getContentHosting()

setContentHosting

public void setContentHosting(ContentHostingService contentHosting)

init

protected void init()
             throws Exception
Throws:
Exception

updateSchemaHash

protected void updateSchemaHash()

calculateSchemaHash

protected String calculateSchemaHash(StructuredArtifactDefinitionBean bean)

packageForDownload

public void packageForDownload(Map params,
                               OutputStream out)
                        throws IOException
Specified by:
packageForDownload in interface DownloadableManager
Throws:
IOException

packageFormForExport

public void packageFormForExport(String formId,
                                 OutputStream os)
                          throws IOException
This is the default method for exporting a form into a stream. This method does check the form export permission.

Specified by:
packageFormForExport in interface StructuredArtifactDefinitionManager
Parameters:
formId - String
os - OutputStream
Throws:
IOException

packageFormForExport

public void packageFormForExport(String formId,
                                 OutputStream os,
                                 boolean checkPermission)
                          throws IOException
This method will export a form into a stream. It has the ability to turn off checking for the export form permission.

Specified by:
packageFormForExport in interface StructuredArtifactDefinitionManager
Parameters:
formId - String
os - OutputStream
checkPermission - boolean
Throws:
IOException

exportSADAsXML

public org.jdom.Document exportSADAsXML(StructuredArtifactDefinitionBean bean)
Given a bean this method will convert it into a new XML document. This does not put the schema into XML

Parameters:
bean - StructuredArtifactDefinitionBean
Returns:
Document - XML

writeSADasXMLtoStream

public void writeSADasXMLtoStream(StructuredArtifactDefinitionBean bean,
                                  OutputStream os)
                           throws IOException
Given a bean, this method puts it into a stream via UTF-8 encoding

Parameters:
bean - StructuredArtifactDefinitionBean
os - OutputStream
Throws:
IOException

writeSADtoZip

public void writeSADtoZip(StructuredArtifactDefinitionBean bean,
                          ZipOutputStream zos)
                   throws IOException
Throws:
IOException

writeSADtoZip

public void writeSADtoZip(StructuredArtifactDefinitionBean bean,
                          ZipOutputStream zos,
                          String path)
                   throws IOException
Throws:
IOException

importSADResource

public boolean importSADResource(Id worksiteId,
                                 String resourceId,
                                 boolean findExisting)
                          throws IOException,
                                 ServerOverloadException,
                                 PermissionException,
                                 IdUnusedException,
                                 ImportException,
                                 UnsupportedFileTypeException
Given a resource id, this parses out the Form from its input stream. Once the enties are found, they are inserted into the given worksite.

Specified by:
importSADResource in interface StructuredArtifactDefinitionManager
Parameters:
worksiteId - Id
resourceId - an String
findExisting -
Throws:
IOException
ServerOverloadException
PermissionException
IdUnusedException
ImportException
UnsupportedFileTypeException

importSad

public StructuredArtifactDefinitionBean importSad(Id worksiteId,
                                                  InputStream in,
                                                  boolean findExisting,
                                                  boolean publish)
                                           throws IOException,
                                                  ImportException
Specified by:
importSad in interface StructuredArtifactDefinitionManager
Throws:
IOException
ImportException

importSad

public StructuredArtifactDefinitionBean importSad(Id worksiteId,
                                                  InputStream in,
                                                  boolean findExisting,
                                                  boolean publish,
                                                  boolean foundThrowsException)
                                           throws IOException,
                                                  ImportException
Specified by:
importSad in interface StructuredArtifactDefinitionManager
Throws:
IOException
ImportException

findBean

protected StructuredArtifactDefinitionBean findBean(StructuredArtifactDefinitionBean bean)

readSADfromZip

public StructuredArtifactDefinitionBean readSADfromZip(ZipInputStream zis,
                                                       String worksite,
                                                       boolean publish)
                                                throws IOException
Throws:
IOException

getGlobalSites

public List getGlobalSites()

setGlobalSites

public void setGlobalSites(List globalSites)

getGlobalSiteTypes

public List getGlobalSiteTypes()

setGlobalSiteTypes

public void setGlobalSiteTypes(List globalSiteTypes)

createFormViewXml

public org.jdom.Element createFormViewXml(String formId,
                                          String returnUrl)
Specified by:
createFormViewXml in interface StructuredArtifactDefinitionManager

getArtifactFinder

public ArtifactFinder getArtifactFinder()

setArtifactFinder

public void setArtifactFinder(ArtifactFinder artifactFinder)