org.efaps.update.schema.dbproperty.DBPropertiesUpdate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of efaps-kernel Show documentation
Show all versions of efaps-kernel Show documentation
eFaps is a framework used to map objects with or without attached files to
a relational database and optional file systems (only for attaches files). Configurable access control can be provided down to object and attribute level depending on implementation and use case. Depending on requirements, events (like triggers) allow to implement business logic and to separate business logic from user interface.
The framework includes integrations (e.g. webdav, full text search) and a web application as 'simple' configurable user interface. Some best practises, example web application modules (e.g. team work module) support administrators and implementers using this framework.
/*
* Copyright 2003 - 2012 The eFaps Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Revision: $Rev: 7659 $
* Last Changed: $Date: 2012-06-13 23:23:03 -0500 (Wed, 13 Jun 2012) $
* Last Changed By: $Author: [email protected] $
*/
package org.efaps.update.schema.dbproperty;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.jexl.JexlContext;
import org.efaps.admin.datamodel.Type;
import org.efaps.ci.CIAdmin;
import org.efaps.db.Insert;
import org.efaps.db.Instance;
import org.efaps.db.InstanceQuery;
import org.efaps.db.QueryBuilder;
import org.efaps.db.Update;
import org.efaps.update.IUpdate;
import org.efaps.update.Profile;
import org.efaps.update.UpdateLifecycle;
import org.efaps.update.util.InstallationException;
import org.efaps.util.EFapsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Class for importing or updating of Properties from a properties-file into the
* Database for use as eFaps-Admin_Properties.
* The import depends on the UUID of the Bundle. That means all Keys of the
* Properties must be unique within a Bundle. Therefore the import will update a
* key, if it is already existing inside this bundle. The Bundle will always be
* identified by the UUID and not by the name.
*
* @author The eFaps Team
* @version $Id: DBPropertiesUpdate.java 7659 2012-06-14 04:23:03Z [email protected] $
*/
public class DBPropertiesUpdate
implements IUpdate
{
/**
* name for the Type.
*/
private static final String TYPE_PROPERTIES = "Admin_Common_DBProperties";
/**
* name for the Type.
*/
private static final String TYPE_PROPERTIES_BUNDLE = "Admin_Common_DBPropertiesBundle";
/**
* name for the Type.
*/
private static final String TYPE_PROPERTIES_LOCAL = "Admin_Common_DBPropertiesLocal";
/**
* Logging instance used to give logging information of this class.
*/
private static final Logger LOG = LoggerFactory.getLogger(DBPropertiesUpdate.class);
/**
* the name of the Bundle.
*/
private String bundlename;
/**
* the UUID of the Bundle.
*/
private String bundeluuid;
/**
* the ID of the Bundle.
*/
private long bundleid;
/**
* Sequence of the Bundle.
*/
private String bundlesequence;
/**
* root of the XML-file to be imported.
*/
private final String root;
/**
* List of all Resources in this Properties.
*/
private final List resources = new ArrayList();
/**
* Name of the application.
*/
private String fileApplication;
/**
* Current read source.
* @see #readXML(List, Map, String)
*/
private Resource curResource;
/**
* @param _url url for the file
*/
public DBPropertiesUpdate(final URL _url)
{
final String urlStr = _url.toString();
this.root = urlStr.substring(0, urlStr.lastIndexOf(File.separator) + 1);
}
/**
* find out the Id of the language used for this properties.
* @param _language Language
* @return ID of the Language
*/
private Long getLanguageId(final String _language)
{
Long ret = null;
try {
final QueryBuilder queryBldr = new QueryBuilder(CIAdmin.Language);
queryBldr.addWhereAttrEqValue(CIAdmin.Language.Language, _language);
final InstanceQuery query = queryBldr.getQuery();
query.executeWithoutAccessCheck();
if (query.next()) {
ret = query.getCurrentValue().getId();
} else {
ret = insertNewLanguage(_language);
}
} catch (final EFapsException e) {
DBPropertiesUpdate.LOG.error("getLanguageId()", e);
}
return ret;
}
/**
* inserts a new language into the Database.
*
* @param _language language to be inserted
* @return ID of the new language
*/
private long insertNewLanguage(final String _language)
{
Long ret = null;
try {
final Insert insert = new Insert(CIAdmin.Language);
insert.add(CIAdmin.Language.Language, _language);
insert.executeWithoutAccessCheck();
ret = insert.getId();
insert.close();
} catch (final EFapsException e) {
DBPropertiesUpdate.LOG.error("insertNewLanguage()", e);
}
return ret;
}
/**
* Insert a new Bundle into the Database.
*
* @return ID of the new Bundle
*/
private long insertNewBundle()
{
Long ret = null;
try {
final Insert insert = new Insert(DBPropertiesUpdate.TYPE_PROPERTIES_BUNDLE);
insert.add("Name", this.bundlename);
insert.add("UUID", this.bundeluuid);
insert.add("Sequence", this.bundlesequence);
insert.executeWithoutAccessCheck();
ret = insert.getId();
insert.close();
} catch (final EFapsException e) {
DBPropertiesUpdate.LOG.error("insertNewBundle()", e);
}
return ret;
}
/**
* Import Properties from a Properties-File as default, if the key is
* already existing, the default will be replaced with the new default.
*
* @param _url Complete Path/Name of the property file to import
*/
private void importFromProperties(final URL _url)
{
try {
final InputStream propInFile = _url.openStream();
final Properties props = new Properties();
props.load(propInFile);
final Iterator> iter = props.entrySet().iterator();
while (iter.hasNext()) {
final Entry