tim-connector: Created new entity Connector based on AppProperties
AppProperties entity has been removed as it stores the same information (majorId) repeated in each database record and it doesn't match with the real model that we need. A new entity Connector with a majorId identifier has been created, this entity contains a list of properties (pairs key-value). Moreover it has been created the predefined Tim connector with its own properties (predefined too). For new connectors, apart from the specific classes implementing them it would be only needed to modify PredefinedConnectors and PredefinedConnectorProperties. The database will be updated automatically on LibrePlan startup thanks to the ConnectorBootstrap. FEA: ItEr77S16JiraAndTimConnectorContributionIntegration
This commit is contained in:
parent
4aae86335e
commit
c29015e9af
22 changed files with 651 additions and 352 deletions
|
|
@ -28,6 +28,7 @@ import org.libreplan.business.calendars.daos.ICalendarDataDAO;
|
|||
import org.libreplan.business.calendars.daos.ICalendarExceptionDAO;
|
||||
import org.libreplan.business.calendars.daos.ICalendarExceptionTypeDAO;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.daos.IConnectorDAO;
|
||||
import org.libreplan.business.common.daos.IEntitySequenceDAO;
|
||||
import org.libreplan.business.costcategories.daos.ICostCategoryDAO;
|
||||
import org.libreplan.business.costcategories.daos.IHourCostDAO;
|
||||
|
|
@ -203,6 +204,9 @@ public class Registry {
|
|||
@Autowired
|
||||
private IOrderAuthorizationDAO orderAuthorizationDAO;
|
||||
|
||||
@Autowired
|
||||
private IConnectorDAO connectorDAO;
|
||||
|
||||
@Autowired
|
||||
private IAdHocTransactionService transactionServiceDAO;
|
||||
|
||||
|
|
@ -379,4 +383,8 @@ public class Registry {
|
|||
return getInstance().orderAuthorizationDAO;
|
||||
}
|
||||
|
||||
public static IConnectorDAO getConnectorDAO() {
|
||||
return getInstance().connectorDAO;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,58 +19,57 @@
|
|||
|
||||
package org.libreplan.business.common.daos;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.libreplan.business.common.entities.AppProperties;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* DAO for {@link AppProperties}
|
||||
* DAO for {@link Connector} entity.
|
||||
*
|
||||
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class AppPropertiesDAO extends GenericDAOHibernate<AppProperties, Long>
|
||||
implements IAppPropertiesDAO {
|
||||
public class ConnectorDAO extends GenericDAOHibernate<Connector, Long>
|
||||
implements IConnectorDAO {
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<AppProperties> getAll() {
|
||||
return list(AppProperties.class);
|
||||
public List<Connector> getAll() {
|
||||
return list(Connector.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, String> findByMajorId(String majorId) {
|
||||
Criteria c = getSession().createCriteria(AppProperties.class).add(
|
||||
public Connector findUniqueByMajorId(String majorId) {
|
||||
Criteria c = getSession().createCriteria(Connector.class).add(
|
||||
Restrictions.eq("majorId", majorId));
|
||||
List<AppProperties> list = c.list();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for (AppProperties appProperty : list) {
|
||||
map.put(appProperty.getPropertyName(),
|
||||
appProperty.getPropertyValue());
|
||||
}
|
||||
return map;
|
||||
|
||||
return (Connector) c.uniqueResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public AppProperties findByMajorIdAndName(String majorId, String proprtyName) {
|
||||
return (AppProperties) getSession().createCriteria(AppProperties.class)
|
||||
.add(Restrictions.eq("majorId", majorId))
|
||||
.add(Restrictions.eq("propertyName", proprtyName))
|
||||
.uniqueResult();
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public boolean existsByNameAnotherTransaction(Connector connector) {
|
||||
return existsOtherConnectorByMajorId(connector);
|
||||
}
|
||||
|
||||
private boolean existsOtherConnectorByMajorId(Connector connector) {
|
||||
Connector found = findUniqueByMajorId(connector.getMajorId());
|
||||
return found != null && found != connector;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public Connector findUniqueByMajorIdAnotherTransaction(String majorId) {
|
||||
return findUniqueByMajorId(majorId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -20,21 +20,23 @@
|
|||
package org.libreplan.business.common.daos;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.libreplan.business.common.entities.AppProperties;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
|
||||
/**
|
||||
* Contract for {@link AppPropertiesDAO}
|
||||
* Contract for {@link Conn}
|
||||
*
|
||||
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public interface IAppPropertiesDAO extends IGenericDAO<AppProperties, Long> {
|
||||
public interface IConnectorDAO extends IGenericDAO<Connector, Long> {
|
||||
|
||||
List<AppProperties> getAll();
|
||||
List<Connector> getAll();
|
||||
|
||||
Map<String, String> findByMajorId(String majorId);
|
||||
Connector findUniqueByMajorId(String majorId);
|
||||
|
||||
AppProperties findByMajorIdAndName(String majorId, String proprtyName);
|
||||
boolean existsByNameAnotherTransaction(Connector connector);
|
||||
|
||||
Connector findUniqueByMajorIdAnotherTransaction(String majorId);
|
||||
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2013 St. Antoniusziekenhuis
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.business.common.entities;
|
||||
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.libreplan.business.common.BaseEntity;
|
||||
|
||||
/**
|
||||
* AppProperties Entity, represents application configuration parameters.
|
||||
*
|
||||
* This property can be used by all applications who needs simple name-value
|
||||
* pair configurations. It consists the following properties:
|
||||
* <ul>
|
||||
* <li>majorId: an indication for some large piece of functionality like "jira"
|
||||
* for "jira-connector"</li>
|
||||
* <li>minorId: used for sub module within this majorId. It can be null if not
|
||||
* used</li>
|
||||
* <li>propertyName: holder for the name of a property</li>
|
||||
* <li>propertyValue: holder for the value of a property</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
|
||||
*/
|
||||
public class AppProperties extends BaseEntity {
|
||||
|
||||
public static AppProperties create() {
|
||||
return create(new AppProperties());
|
||||
}
|
||||
|
||||
private String majorId;
|
||||
|
||||
private String minorId;
|
||||
|
||||
private String propertyName;
|
||||
|
||||
private String propertyValue;
|
||||
|
||||
/**
|
||||
* Constructor for Hibernate. Do not use!
|
||||
*/
|
||||
protected AppProperties() {
|
||||
}
|
||||
|
||||
@NotNull(message = "majorId not specified")
|
||||
public String getMajorId() {
|
||||
return majorId;
|
||||
}
|
||||
|
||||
public void setMajorId(String majorId) {
|
||||
this.majorId = majorId;
|
||||
}
|
||||
|
||||
public String getMinorId() {
|
||||
return minorId;
|
||||
}
|
||||
|
||||
public void setMinorId(String minorId) {
|
||||
this.minorId = minorId;
|
||||
}
|
||||
|
||||
@NotNull(message = "property name not specified")
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public void setPropertyName(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
@NotNull(message = "property value not specified")
|
||||
public String getPropertyValue() {
|
||||
return propertyValue;
|
||||
}
|
||||
|
||||
public void setPropertyValue(String propertyValue) {
|
||||
this.propertyValue = propertyValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2013 St. Antoniusziekenhuis
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.business.common.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.hibernate.validator.Valid;
|
||||
import org.libreplan.business.common.BaseEntity;
|
||||
import org.libreplan.business.common.Registry;
|
||||
import org.libreplan.business.common.daos.IConnectorDAO;
|
||||
|
||||
/**
|
||||
* Connector entity, represents a connector in order that LibrePlan interchange
|
||||
* some data with other application.
|
||||
*
|
||||
* A connector is identified by a string called <code>majorId</code> and it has
|
||||
* a list of pairs key-value in order to store the configuration parameters of
|
||||
* the connector.
|
||||
*
|
||||
* This entity should be used to create new connectors in LibrePlan.
|
||||
*
|
||||
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public class Connector extends BaseEntity {
|
||||
|
||||
public static Connector create(String majorId) {
|
||||
return create(new Connector(majorId));
|
||||
}
|
||||
|
||||
private String majorId;
|
||||
|
||||
private List<ConnectorProperty> properties = new ArrayList<ConnectorProperty>();
|
||||
|
||||
/**
|
||||
* Constructor for Hibernate. Do not use!
|
||||
*/
|
||||
protected Connector() {
|
||||
}
|
||||
|
||||
private Connector(String majorId) {
|
||||
this.majorId = majorId;
|
||||
}
|
||||
|
||||
@NotEmpty(message = "major id not specified")
|
||||
public String getMajorId() {
|
||||
return majorId;
|
||||
}
|
||||
|
||||
public void setMajorId(String majorId) {
|
||||
this.majorId = majorId;
|
||||
}
|
||||
|
||||
@Valid
|
||||
public List<ConnectorProperty> getProperties() {
|
||||
return Collections.unmodifiableList(properties);
|
||||
}
|
||||
|
||||
public void setProperties(List<ConnectorProperty> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public void addProperty(ConnectorProperty property) {
|
||||
properties.add(property);
|
||||
}
|
||||
|
||||
public Map<String, String> getPropertiesAsMap() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for (ConnectorProperty property : properties) {
|
||||
map.put(property.getKey(), property.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "connector major id is already being used")
|
||||
public boolean checkConstraintUniqueConnectorMajorId() {
|
||||
if (StringUtils.isBlank(majorId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
IConnectorDAO connectorDAO = Registry.getConnectorDAO();
|
||||
if (isNewObject()) {
|
||||
return !connectorDAO.existsByNameAnotherTransaction(this);
|
||||
} else {
|
||||
Connector found = connectorDAO
|
||||
.findUniqueByMajorIdAnotherTransaction(majorId);
|
||||
return found == null || found.getId().equals(getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2013 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.business.common.entities;
|
||||
|
||||
import org.libreplan.business.common.daos.IConnectorDAO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Creates the LibrePlan {@link Connector Connectors} with its configuration
|
||||
* properties and default values.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class ConnectorBootstrap implements IConnectorBootstrap {
|
||||
|
||||
@Autowired
|
||||
private IConnectorDAO connectorDAO;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void loadRequiredData() {
|
||||
for (PredefinedConnectors predefinedConnector : PredefinedConnectors
|
||||
.values()) {
|
||||
String majorId = predefinedConnector.getMajorId();
|
||||
|
||||
Connector connector = connectorDAO.findUniqueByMajorId(majorId);
|
||||
if (connector == null) {
|
||||
connector = Connector.create(majorId);
|
||||
connector.setProperties(predefinedConnector.getProperties());
|
||||
connectorDAO.save(connector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2013 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.business.common.entities;
|
||||
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
|
||||
/**
|
||||
* This class is intended to work as a Hibernate component. It's formed by two
|
||||
* attributes, the key and the value of the property. It represents the
|
||||
* different configuration parameters of a {@link Connector}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class ConnectorProperty {
|
||||
|
||||
public static ConnectorProperty create(String key, String value) {
|
||||
return new ConnectorProperty(key, value);
|
||||
}
|
||||
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* Default constructor for Hibernate. Do not use!
|
||||
*/
|
||||
protected ConnectorProperty() {
|
||||
}
|
||||
|
||||
private ConnectorProperty(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@NotEmpty(message = "property key not specified")
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2013 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.business.common.entities;
|
||||
|
||||
import org.libreplan.business.IDataBootstrap;
|
||||
|
||||
/**
|
||||
* Contract for {@link ConnectorBootstrap}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public interface IConnectorBootstrap extends IDataBootstrap {
|
||||
|
||||
void loadRequiredData();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2013 St. Antoniusziekenhuis
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.business.common.entities;
|
||||
|
||||
import static org.libreplan.business.i18n.I18nHelper._;
|
||||
|
||||
/**
|
||||
* Simply class to keep constants of {@link ConnectorProperty properties} for
|
||||
* LibrePlan {@link Connector connectors}.
|
||||
*
|
||||
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public class PredefinedConnectorProperties {
|
||||
|
||||
// Generic
|
||||
public static String ACTIVATED = _("Activated");
|
||||
public static String SERVER_URL = _("Server URL");
|
||||
public static String USERNAME = _("Username");
|
||||
public static String PASSWORD = _("Password");
|
||||
|
||||
// Specific for Tim
|
||||
public static String TIM_NR_DAYS_TIMESHEET = _("Number of days timesheet to Tim");
|
||||
public static String TIM_NR_DAYS_ROSTER = _("Number of days roster from Tim");
|
||||
public static String TIM_PRODUCTIVITY_FACTOR = _("Productivity factor");
|
||||
public static String TIM_DEPARTAMENTS_IMPORT_ROSTER = _("Department IDs to import toster");
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2013 St. Antoniusziekenhuis
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.business.common.entities;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Defines the LibrePlan {@link Connector Connectors} together with its
|
||||
* configuration properties.
|
||||
*
|
||||
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public enum PredefinedConnectors {
|
||||
|
||||
TIM("Tim",
|
||||
ConnectorProperty.create(PredefinedConnectorProperties.ACTIVATED, "N"),
|
||||
ConnectorProperty.create(PredefinedConnectorProperties.SERVER_URL, ""),
|
||||
ConnectorProperty.create(PredefinedConnectorProperties.USERNAME, ""),
|
||||
ConnectorProperty.create(PredefinedConnectorProperties.PASSWORD, ""),
|
||||
ConnectorProperty.create(PredefinedConnectorProperties.TIM_NR_DAYS_TIMESHEET, "7"),
|
||||
ConnectorProperty.create(PredefinedConnectorProperties.TIM_NR_DAYS_ROSTER, "90"),
|
||||
ConnectorProperty.create(PredefinedConnectorProperties.TIM_PRODUCTIVITY_FACTOR, "100"),
|
||||
ConnectorProperty.create(PredefinedConnectorProperties.TIM_DEPARTAMENTS_IMPORT_ROSTER, "0")
|
||||
);
|
||||
|
||||
private String majorId;
|
||||
private List<ConnectorProperty> properties;
|
||||
|
||||
private PredefinedConnectors(String majorId,
|
||||
ConnectorProperty... properties) {
|
||||
this.majorId = majorId;
|
||||
this.properties = Arrays.asList(properties);
|
||||
}
|
||||
|
||||
public String getMajorId() {
|
||||
return majorId;
|
||||
}
|
||||
|
||||
public List<ConnectorProperty> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -334,65 +334,51 @@
|
|||
baseTableName="order_sync_info" baseColumnNames="order_element_id"
|
||||
referencedTableName="order_table" referencedColumnNames="order_element_id" />
|
||||
</changeSet>
|
||||
<!-- app properties -->
|
||||
<changeSet author="miciele" id="create-table-app-properties">
|
||||
<comment>Create new table app_properties</comment>
|
||||
<createTable tableName="app_properties">
|
||||
|
||||
<!-- connector -->
|
||||
<changeSet author="rego" id="create-tables-related-to-connector-entity">
|
||||
<comment>Create tables related to Connector entity</comment>
|
||||
<createTable tableName="connector">
|
||||
<column name="id" type="BIGINT" autoIncrement="true">
|
||||
<constraints nullable="false"/>
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="connector_pkey" />
|
||||
</column>
|
||||
<column name="version" type="BIGINT">
|
||||
<constraints nullable="false" />
|
||||
</column>
|
||||
<column name="major_id" type="VARCHAR(255)" >
|
||||
<constraints nullable="false" primaryKey="true" />
|
||||
<constraints nullable="false" />
|
||||
</column>
|
||||
<column name="minor_id" type="VARCHAR(255)" />
|
||||
<column name="property_name" type="VARCHAR(255)" >
|
||||
<constraints nullable="false" primaryKey="true" />
|
||||
</column>
|
||||
<column name="property_value" type="VARCHAR(255)" />
|
||||
</createTable>
|
||||
|
||||
<createTable tableName="connector_property">
|
||||
<column name="connector_id" type="BIGINT">
|
||||
<constraints nullable="false" />
|
||||
</column>
|
||||
<column name="connector_property_position" type="INTEGER">
|
||||
<constraints nullable="false" />
|
||||
</column>
|
||||
<column name="key" type="VARCHAR(255)">
|
||||
<constraints nullable="false" />
|
||||
</column>
|
||||
<column name="value" type="VARCHAR(255)" />
|
||||
</createTable>
|
||||
|
||||
<addPrimaryKey
|
||||
columnNames="connector_id,connector_property_position"
|
||||
constraintName="connector_property_pkey"
|
||||
tableName="connector_property"/>
|
||||
|
||||
<addForeignKeyConstraint
|
||||
baseColumnNames="connector_id"
|
||||
baseTableName="connector_property"
|
||||
constraintName="connector_property_connector_id_fkey"
|
||||
deferrable="false" initiallyDeferred="false"
|
||||
onDelete="NO ACTION" onUpdate="NO ACTION"
|
||||
referencedColumnNames="id"
|
||||
referencedTableName="connector"
|
||||
referencesUniqueColumn="false"/>
|
||||
</changeSet>
|
||||
<changeSet author="miciele" id="insert-predefined-names">
|
||||
<comment>Insert some default keys and values</comment>
|
||||
<insert tableName="app_properties">
|
||||
<column name="major_id" value="Tim"/>
|
||||
<column name="version" value="0"/>
|
||||
<column name="property_name" value="Activated" />
|
||||
<column name="property_value" value="Y" />
|
||||
</insert>
|
||||
<insert tableName="app_properties">
|
||||
<column name="major_id" value="Tim"/>
|
||||
<column name="version" value="0"/>
|
||||
<column name="property_name" value="Server" />
|
||||
<column name="property_value" value="http://azn-svap270.amg.local:10980/impexp/" />
|
||||
</insert>
|
||||
<insert tableName="app_properties">
|
||||
<column name="major_id" value="Tim"/>
|
||||
<column name="version" value="0"/>
|
||||
<column name="property_name" value="Username" />
|
||||
<column name="property_value" value="timnsoap" />
|
||||
</insert>
|
||||
<insert tableName="app_properties">
|
||||
<column name="major_id" value="Tim"/>
|
||||
<column name="version" value="0"/>
|
||||
<column name="property_name" value="Password" />
|
||||
<column name="property_value" value="aenova" />
|
||||
</insert>
|
||||
<insert tableName="app_properties">
|
||||
<column name="major_id" value="Tim"/>
|
||||
<column name="version" value="0"/>
|
||||
<column name="property_name" value="NrDaysTimesheetToTim" />
|
||||
<column name="property_value" value="7" />
|
||||
</insert>
|
||||
<insert tableName="app_properties">
|
||||
<column name="major_id" value="Tim"/>
|
||||
<column name="version" value="0"/>
|
||||
<column name="property_name" value="NrDaysRosterFromTim" />
|
||||
<column name="property_value" value="90" />
|
||||
</insert>
|
||||
</changeSet>
|
||||
|
||||
<!-- scheduler configuration -->
|
||||
<changeSet author="miciele" id="create-table-job-scheduler-configuration">
|
||||
<comment>Create new table job_scheduler_configuration</comment>
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@
|
|||
org/libreplan/business/expensesheets/entities/ExpenseSheets.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/libreplan/business/common/entities/AppProperties.hbm.xml
|
||||
org/libreplan/business/common/entities/Connector.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/libreplan/business/common/entities/JobSchedulerConfiguration.hbm.xml
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<hibernate-mapping default-access="field"
|
||||
package="org.libreplan.business.common.entities">
|
||||
|
||||
<class name="AppProperties" table="app_properties">
|
||||
<class name="Connector" table="connector">
|
||||
<id name="id" column="id" type="long" access="property">
|
||||
<generator class="hilo">
|
||||
<param name="max_lo">100</param>
|
||||
|
|
@ -13,9 +13,18 @@
|
|||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="majorId" column="major_id" not-null="true" />
|
||||
<property name="minorId" column="minor_id" />
|
||||
<property name="propertyName" column="property_name" not-null="true"/>
|
||||
<property name="propertyValue" column="property_value" not-null="true"/>
|
||||
|
||||
<list name="properties" table="connector_property">
|
||||
<key column="connector_id" />
|
||||
<list-index column="connector_property_position" />
|
||||
|
||||
<composite-element class="ConnectorProperty">
|
||||
<property name="key" column="key"
|
||||
not-null="true" />
|
||||
<property name="value" column="value" />
|
||||
</composite-element>
|
||||
</list>
|
||||
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
|
@ -30,8 +30,11 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.common.IAdHocTransactionService;
|
||||
import org.libreplan.business.common.IOnTransaction;
|
||||
import org.libreplan.business.common.daos.IAppPropertiesDAO;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.daos.IConnectorDAO;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
import org.libreplan.business.common.entities.PredefinedConnectorProperties;
|
||||
import org.libreplan.business.common.entities.PredefinedConnectors;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.orders.daos.IOrderDAO;
|
||||
import org.libreplan.business.orders.daos.IOrderSyncInfoDAO;
|
||||
|
|
@ -83,29 +86,31 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
private IAdHocTransactionService adHocTransactionService;
|
||||
|
||||
@Autowired
|
||||
private IAppPropertiesDAO appPropertiesDAO;
|
||||
private IConnectorDAO connectorDAO;
|
||||
|
||||
@Autowired
|
||||
private IOrderDAO orderDAO;
|
||||
|
||||
private static final String CONNECTOR_MAJOR_ID = "Tim";
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void exportTimesheets() {
|
||||
Map<String, String> prop = appPropertiesDAO
|
||||
.findByMajorId(CONNECTOR_MAJOR_ID);
|
||||
String majorId = PredefinedConnectors.TIM.getMajorId();
|
||||
Connector connector = connectorDAO.findUniqueByMajorId(majorId);
|
||||
if (connector == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Order> orders = orderDAO.getOrders();
|
||||
for (Order order : orders) {
|
||||
OrderSyncInfo orderSyncInfo = orderSyncInfoDAO
|
||||
.findLastSynchronizedInfoByOrderAndConnectorId(order,
|
||||
CONNECTOR_MAJOR_ID);
|
||||
majorId);
|
||||
if (orderSyncInfo == null) {
|
||||
LOG.warn("Order '" + order.getName()
|
||||
+ "' is not yet synchronized");
|
||||
} else {
|
||||
boolean result = exportTimesheets(orderSyncInfo.getKey(),
|
||||
orderSyncInfo.getOrder(), prop);
|
||||
orderSyncInfo.getOrder(), connector);
|
||||
LOG.info("Export successful: " + result);
|
||||
}
|
||||
}
|
||||
|
|
@ -120,11 +125,13 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
if (order == null) {
|
||||
throw new RuntimeException("Order should not be empty");
|
||||
}
|
||||
Connector connector = connectorDAO
|
||||
.findUniqueByMajorId(PredefinedConnectors.TIM.getMajorId());
|
||||
if (connector == null) {
|
||||
throw new RuntimeException("Tim connector not found");
|
||||
}
|
||||
|
||||
Map<String, String> prop = appPropertiesDAO
|
||||
.findByMajorId(CONNECTOR_MAJOR_ID);
|
||||
return exportTimesheets(productCode, order, prop);
|
||||
|
||||
return exportTimesheets(productCode, order, connector);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,19 +141,22 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
* the product code
|
||||
* @param order
|
||||
* the order
|
||||
* @param appProperties
|
||||
* the app properties
|
||||
* @param connector
|
||||
* the connector
|
||||
*
|
||||
* @return true if export is succeeded, false otherwise
|
||||
*/
|
||||
private boolean exportTimesheets(String productCode, Order order,
|
||||
Map<String, String> appProperties) {
|
||||
Connector connector) {
|
||||
Map<String, String> properties = connector.getPropertiesAsMap();
|
||||
|
||||
String url = appProperties.get("Server");
|
||||
String userName = appProperties.get("Username");
|
||||
String password = appProperties.get("Password");
|
||||
int nrDaysTimesheetToTim = Integer.parseInt(appProperties
|
||||
.get("NrDaysTimesheetToTim"));
|
||||
String url = properties.get(PredefinedConnectorProperties.SERVER_URL);
|
||||
String userName = properties
|
||||
.get(PredefinedConnectorProperties.USERNAME);
|
||||
String password = properties
|
||||
.get(PredefinedConnectorProperties.PASSWORD);
|
||||
int nrDaysTimesheetToTim = Integer.parseInt(properties
|
||||
.get(PredefinedConnectorProperties.TIM_NR_DAYS_TIMESHEET));
|
||||
|
||||
LocalDate dateNrOfDaysBack = new LocalDate()
|
||||
.minusDays(nrDaysTimesheetToTim);
|
||||
|
|
@ -219,7 +229,7 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
@Override
|
||||
public Void execute() {
|
||||
OrderSyncInfo orderSyncInfo = OrderSyncInfo.create(
|
||||
order, CONNECTOR_MAJOR_ID);
|
||||
order, PredefinedConnectors.TIM.getMajorId());
|
||||
orderSyncInfo.setKey(productCode);
|
||||
orderSyncInfoDAO.save(orderSyncInfo);
|
||||
return null;
|
||||
|
|
@ -276,7 +286,7 @@ public class ExportTimesheetsToTim implements IExportTimesheetsToTim {
|
|||
@Transactional(readOnly = true)
|
||||
public OrderSyncInfo getOrderLastSyncInfo(Order order) {
|
||||
return orderSyncInfoDAO.findLastSynchronizedInfoByOrderAndConnectorId(
|
||||
order, CONNECTOR_MAJOR_ID);
|
||||
order, PredefinedConnectors.TIM.getMajorId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.libreplan.importers;
|
||||
|
||||
import org.libreplan.business.common.entities.AppProperties;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
import org.libreplan.business.orders.entities.Order;
|
||||
import org.libreplan.business.orders.entities.OrderSyncInfo;
|
||||
|
||||
|
|
@ -28,8 +28,8 @@ import org.libreplan.business.orders.entities.OrderSyncInfo;
|
|||
* {@link TimSoapClient}.
|
||||
*
|
||||
* It exports the time sheets between periods current-date minus
|
||||
* <code>NrDaysTimesheetToTim</code> specified in configuration entity
|
||||
* {@link AppProperties} and the current-date
|
||||
* <code>NrDaysTimesheetToTim</code> specified in the Tim {@link Connector} and
|
||||
* the current-date
|
||||
*
|
||||
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,15 +20,14 @@
|
|||
package org.libreplan.importers;
|
||||
|
||||
import org.libreplan.business.calendars.entities.CalendarException;
|
||||
import org.libreplan.business.common.entities.AppProperties;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
|
||||
/**
|
||||
* Import Rosters from Tim SOAP server using {@link TimSoapClient} and updates
|
||||
* worker's Exception calendar accordingly
|
||||
*
|
||||
* It imports the Rosters between periods current-date and current-date plus
|
||||
* <code>NrDaysRosterFromTim</code> specified in configuration entity
|
||||
* {@link AppProperties}
|
||||
* <code>NrDaysRosterFromTim</code> specified in Tim {@link Connector}.
|
||||
*
|
||||
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -38,8 +38,11 @@ import org.libreplan.business.calendars.entities.PredefinedCalendarExceptionType
|
|||
import org.libreplan.business.calendars.entities.ResourceCalendar;
|
||||
import org.libreplan.business.common.IAdHocTransactionService;
|
||||
import org.libreplan.business.common.IOnTransaction;
|
||||
import org.libreplan.business.common.daos.IAppPropertiesDAO;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.daos.IConnectorDAO;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
import org.libreplan.business.common.entities.PredefinedConnectorProperties;
|
||||
import org.libreplan.business.common.entities.PredefinedConnectors;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.resources.daos.IResourceDAO;
|
||||
import org.libreplan.business.resources.daos.IWorkerDAO;
|
||||
|
|
@ -88,7 +91,7 @@ public class ImportRosterFromTim implements IImportRosterFromTim {
|
|||
private IWorkerModel workerModel;
|
||||
|
||||
@Autowired
|
||||
private IAppPropertiesDAO appPropertiesDAO;
|
||||
private IConnectorDAO connectorDAO;
|
||||
|
||||
@Autowired
|
||||
private IAdHocTransactionService adHocTransactionService;
|
||||
|
|
@ -122,19 +125,29 @@ public class ImportRosterFromTim implements IImportRosterFromTim {
|
|||
@Override
|
||||
@Transactional
|
||||
public void importRosters() {
|
||||
Map<String, String> prop = appPropertiesDAO.findByMajorId("Tim");
|
||||
String url = prop.get("Server");
|
||||
String userName = prop.get("Username");
|
||||
String password = prop.get("Password");
|
||||
Connector connector = connectorDAO
|
||||
.findUniqueByMajorId(
|
||||
PredefinedConnectors.TIM.getMajorId());
|
||||
if (connector == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int nrDaysRosterFromTim = Integer.parseInt(prop
|
||||
.get("NrDaysRosterFromTim"));
|
||||
Map<String, String> properties = connector.getPropertiesAsMap();
|
||||
String url = properties.get(PredefinedConnectorProperties.SERVER_URL);
|
||||
String userName = properties
|
||||
.get(PredefinedConnectorProperties.USERNAME);
|
||||
String password = properties
|
||||
.get(PredefinedConnectorProperties.PASSWORD);
|
||||
|
||||
int productivityFactor = Integer.parseInt(prop
|
||||
.get("ProductivityFactor"));
|
||||
int nrDaysRosterFromTim = Integer.parseInt(properties
|
||||
.get(PredefinedConnectorProperties.TIM_NR_DAYS_ROSTER));
|
||||
|
||||
int productivityFactor = Integer.parseInt(properties
|
||||
.get(PredefinedConnectorProperties.TIM_PRODUCTIVITY_FACTOR));
|
||||
|
||||
|
||||
String departmentIds = prop.get("DepartmentIdsToImportRoster");
|
||||
String departmentIds = properties
|
||||
.get(PredefinedConnectorProperties.TIM_DEPARTAMENTS_IMPORT_ROSTER);
|
||||
|
||||
if (StringUtils.isEmpty(departmentIds)) {
|
||||
LOG.warn("No departments configured");
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -43,13 +42,16 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.cxf.jaxrs.client.WebClient;
|
||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||
import org.libreplan.business.common.entities.AppProperties;
|
||||
import org.libreplan.business.common.entities.Configuration;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
import org.libreplan.business.common.entities.ConnectorProperty;
|
||||
import org.libreplan.business.common.entities.EntityNameEnum;
|
||||
import org.libreplan.business.common.entities.EntitySequence;
|
||||
import org.libreplan.business.common.entities.JiraConfiguration;
|
||||
import org.libreplan.business.common.entities.LDAPConfiguration;
|
||||
import org.libreplan.business.common.entities.PersonalTimesheetsPeriodicityEnum;
|
||||
import org.libreplan.business.common.entities.PredefinedConnectorProperties;
|
||||
import org.libreplan.business.common.entities.PredefinedConnectors;
|
||||
import org.libreplan.business.common.entities.ProgressType;
|
||||
import org.libreplan.business.common.exceptions.ValidationException;
|
||||
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
|
||||
|
|
@ -130,10 +132,12 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
|
||||
private Radiogroup strategy;
|
||||
|
||||
private Grid appPropertriesGrid;
|
||||
|
||||
private Combobox connectorCombo;
|
||||
|
||||
private Grid connectorPropertriesGrid;
|
||||
|
||||
private Connector selectedConnector;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
|
|
@ -154,7 +158,6 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
messages = new MessagesForUser(messagesContainer);
|
||||
reloadEntitySequences();
|
||||
loadRoleStrategyRows();
|
||||
reloadAppPropertyConnectors();
|
||||
}
|
||||
|
||||
public void changeRoleStrategy() {
|
||||
|
|
@ -227,6 +230,7 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
messages.showMessage(Level.INFO, _("Changes saved"));
|
||||
reloadWindow();
|
||||
reloadEntitySequences();
|
||||
reloadConnectors();
|
||||
} catch (ValidationException e) {
|
||||
messages.showInvalidValues(e);
|
||||
} catch (ConcurrentModificationException e) {
|
||||
|
|
@ -234,6 +238,7 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
configurationModel.init();
|
||||
reloadWindow();
|
||||
reloadEntitySequences();
|
||||
reloadConnectors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -243,6 +248,7 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
messages.showMessage(Level.INFO, _("Changes have been canceled"));
|
||||
reloadWindow();
|
||||
reloadEntitySequences();
|
||||
reloadConnectors();
|
||||
}
|
||||
|
||||
public void testLDAPConnection() {
|
||||
|
|
@ -316,18 +322,21 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
* Tests connection
|
||||
*/
|
||||
public void testConnection() {
|
||||
String connectorId = getSelectedConnector();
|
||||
if (connectorId == null || connectorId.isEmpty()) {
|
||||
if (selectedConnector == null) {
|
||||
messages.showMessage(Level.ERROR,
|
||||
_("Please select a connector to test it"));
|
||||
return;
|
||||
}
|
||||
Map<String, String> appProperties = getAppProperties(connectorId);
|
||||
String url = appProperties.get("Server");
|
||||
String username = appProperties.get("Username");
|
||||
String password = appProperties.get("Password");
|
||||
|
||||
if (connectorId.equals("Tim")) {
|
||||
Map<String, String> properties = selectedConnector.getPropertiesAsMap();
|
||||
String url = properties.get(PredefinedConnectorProperties.SERVER_URL);
|
||||
String username = properties
|
||||
.get(PredefinedConnectorProperties.USERNAME);
|
||||
String password = properties
|
||||
.get(PredefinedConnectorProperties.PASSWORD);
|
||||
|
||||
if (selectedConnector.getMajorId().equals(
|
||||
PredefinedConnectors.TIM.getMajorId())) {
|
||||
testTimConnection(url, username, password);
|
||||
} else {
|
||||
throw new RuntimeException("Unknown connector");
|
||||
|
|
@ -353,16 +362,6 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
|
||||
private Map<String, String> getAppProperties(String majorConnectorId) {
|
||||
List<AppProperties> appProperties = configurationModel
|
||||
.getAllAppPropertiesByMajorId(majorConnectorId);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for (AppProperties appProp : appProperties) {
|
||||
map.put(appProp.getPropertyName(), appProp.getPropertyValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private boolean checkValidEntitySequenceRows() {
|
||||
Rows rows = entitySequencesGrid.getRows();
|
||||
for (Row row : (List<Row>) rows.getChildren()) {
|
||||
|
|
@ -406,6 +405,14 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
entitySequencesGrid.invalidate();
|
||||
}
|
||||
|
||||
private void reloadConnectors() {
|
||||
selectedConnector = configurationModel
|
||||
.getConnectorByMajorId(selectedConnector != null ? selectedConnector
|
||||
.getMajorId() : null);
|
||||
Util.reloadBindings(connectorCombo);
|
||||
Util.reloadBindings(connectorPropertriesGrid);
|
||||
}
|
||||
|
||||
public String getCompanyCode() {
|
||||
return configurationModel.getCompanyCode();
|
||||
}
|
||||
|
|
@ -1044,69 +1051,58 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
configurationModel.setJiraConnectorTypeOfWorkHours(typeOfWorkHours);
|
||||
}
|
||||
|
||||
private void reloadAppPropertyConnectors() {
|
||||
getAppPropertyConnectors();
|
||||
public List<Connector> getConnectors() {
|
||||
return configurationModel.getConnectors();
|
||||
}
|
||||
|
||||
public Set<String> getAppPropertyConnectors() {
|
||||
return getAllAppProperties().keySet();
|
||||
public Connector getSelectedConnector() {
|
||||
return selectedConnector;
|
||||
}
|
||||
|
||||
private Map<String, List<AppProperties>> getAllAppProperties() {
|
||||
return configurationModel.getAppProperties();
|
||||
|
||||
public void setSelectedConnector(Connector connector) {
|
||||
selectedConnector = connector;
|
||||
Util.reloadBindings(connectorPropertriesGrid);
|
||||
}
|
||||
|
||||
public String getSelectedConnector() {
|
||||
String connectorId = configurationModel.getAppConnectorId();
|
||||
return connectorId;
|
||||
}
|
||||
|
||||
public void setSelectedConnector(String connectorId) {
|
||||
configurationModel.setAppConnectorId(connectorId);
|
||||
Util.reloadBindings(appPropertriesGrid);
|
||||
}
|
||||
|
||||
public List<AppProperties> getAppPropertries() {
|
||||
String appConnectorId = configurationModel.getAppConnectorId();
|
||||
if (StringUtils.isEmpty(appConnectorId)) {
|
||||
public List<ConnectorProperty> getConnectorPropertries() {
|
||||
if (selectedConnector == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return configurationModel.getAllAppPropertiesByMajorId(appConnectorId);
|
||||
return selectedConnector.getProperties();
|
||||
}
|
||||
|
||||
public RowRenderer getAppPropertriesRenderer() {
|
||||
public RowRenderer getConnectorPropertriesRenderer() {
|
||||
return new RowRenderer() {
|
||||
@Override
|
||||
public void render(Row row, Object data) {
|
||||
AppProperties appProperties = (AppProperties) data;
|
||||
row.setValue(appProperties);
|
||||
ConnectorProperty property = (ConnectorProperty) data;
|
||||
row.setValue(property);
|
||||
|
||||
Util.appendLabel(row, appProperties.getPropertyName());
|
||||
appendValueTextbox(row, appProperties);
|
||||
Util.appendLabel(row, _(property.getKey()));
|
||||
appendValueTextbox(row, property);
|
||||
}
|
||||
|
||||
private void appendValueTextbox(Row row,
|
||||
final AppProperties appProperties) {
|
||||
final ConnectorProperty property) {
|
||||
final Textbox textbox = new Textbox();
|
||||
textbox.setWidth("400px");
|
||||
textbox.setConstraint(checkPropertyValue((AppProperties) row
|
||||
.getValue()));
|
||||
textbox.setConstraint(checkPropertyValue(property));
|
||||
|
||||
Util.bind(textbox, new Util.Getter<String>() {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return appProperties.getPropertyValue();
|
||||
return property.getValue();
|
||||
}
|
||||
}, new Util.Setter<String>() {
|
||||
|
||||
@Override
|
||||
public void set(String value) {
|
||||
appProperties.setPropertyValue(value);
|
||||
property.setValue(value);
|
||||
}
|
||||
});
|
||||
if (appProperties.getPropertyName().equals("Password")) {
|
||||
if (property.getKey().equals(
|
||||
PredefinedConnectorProperties.PASSWORD)) {
|
||||
textbox.setType("password");
|
||||
}
|
||||
|
||||
|
|
@ -1114,23 +1110,26 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
public Constraint checkPropertyValue(
|
||||
final AppProperties appProperties) {
|
||||
final String name = appProperties.getPropertyName();
|
||||
final ConnectorProperty property) {
|
||||
final String key = property.getKey();
|
||||
return new Constraint() {
|
||||
@Override
|
||||
public void validate(Component comp, Object value) {
|
||||
if (name.equals("Activated")) {
|
||||
if (!value.equals("Y") && !value.equals("N")) {
|
||||
throw new WrongValueException(comp,
|
||||
_("Only Y/N allowed"));
|
||||
if (key.equals(PredefinedConnectorProperties.ACTIVATED)) {
|
||||
if (!((String) value).equalsIgnoreCase("Y")
|
||||
&& !((String) value).equalsIgnoreCase("N")) {
|
||||
throw new WrongValueException(comp, _(
|
||||
"Only {0} allowed", "Y/N"));
|
||||
}
|
||||
} else if (name.equals("Server")
|
||||
|| name.equals("Username")
|
||||
|| name.equals("Password")) {
|
||||
} else if (key
|
||||
.equals(PredefinedConnectorProperties.SERVER_URL)
|
||||
|| key.equals(PredefinedConnectorProperties.USERNAME)
|
||||
|| key.equals(PredefinedConnectorProperties.PASSWORD)) {
|
||||
((InputElement) comp).setConstraint("no empty:"
|
||||
+ _("cannot be empty"));
|
||||
} else if (name.equals("NrDaysTimesheetToTim")
|
||||
|| name.equals("NrDaysRosterFromTim")) {
|
||||
} else if (key
|
||||
.equals(PredefinedConnectorProperties.TIM_NR_DAYS_TIMESHEET)
|
||||
|| key.equals(PredefinedConnectorProperties.TIM_NR_DAYS_ROSTER)) {
|
||||
if (!isNumeric((String) value)) {
|
||||
throw new WrongValueException(comp,
|
||||
_("Only digits allowed"));
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ import java.util.TreeMap;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.libreplan.business.calendars.daos.IBaseCalendarDAO;
|
||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||
import org.libreplan.business.common.daos.IAppPropertiesDAO;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.daos.IConnectorDAO;
|
||||
import org.libreplan.business.common.daos.IEntitySequenceDAO;
|
||||
import org.libreplan.business.common.entities.AppProperties;
|
||||
import org.libreplan.business.common.entities.Configuration;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
import org.libreplan.business.common.entities.EntityNameEnum;
|
||||
import org.libreplan.business.common.entities.EntitySequence;
|
||||
import org.libreplan.business.common.entities.JiraConfiguration;
|
||||
|
|
@ -79,6 +79,8 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
|
||||
private static Map<String, String> currencies = getAllCurrencies();
|
||||
|
||||
private List<Connector> connectors;
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
|
|
@ -92,11 +94,7 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
private IWorkReportDAO workReportDAO;
|
||||
|
||||
@Autowired
|
||||
IAppPropertiesDAO appPropertiesDAO;
|
||||
|
||||
private Map<String, List<AppProperties>> appPropertiesMap = new HashMap<String, List<AppProperties>>();
|
||||
|
||||
private String connectorId = "Tim";
|
||||
private IConnectorDAO connectorDAO;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
|
|
@ -139,13 +137,13 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
}
|
||||
|
||||
private void initConnectorConfiguration() {
|
||||
this.appPropertiesMap.clear();
|
||||
for (AppProperties appProperties : appPropertiesDAO.getAll()) {
|
||||
if (!this.appPropertiesMap.containsKey(appProperties.getMajorId())) {
|
||||
appPropertiesMap.put(appProperties.getMajorId(),
|
||||
new ArrayList<AppProperties>());
|
||||
}
|
||||
appPropertiesMap.get(appProperties.getMajorId()).add(appProperties);
|
||||
connectors = connectorDAO.getAll();
|
||||
forceLoadConnectors();
|
||||
}
|
||||
|
||||
private void forceLoadConnectors() {
|
||||
for (Connector connector : connectors) {
|
||||
connector.getProperties().size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +187,7 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
public void confirm() {
|
||||
checkEntitySequences();
|
||||
configurationDAO.save(configuration);
|
||||
saveAppProperties();
|
||||
saveConnectors();
|
||||
try {
|
||||
storeAndRemoveEntitySequences();
|
||||
} catch (IllegalStateException e) {
|
||||
|
|
@ -725,37 +723,29 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
}
|
||||
}
|
||||
|
||||
private void saveAppProperties() {
|
||||
for (String appConnectorId : appPropertiesMap.keySet()) {
|
||||
for (AppProperties appProperty : appPropertiesMap
|
||||
.get(appConnectorId)) {
|
||||
appPropertiesDAO.save(appProperty);
|
||||
private void saveConnectors() {
|
||||
for (Connector connector : connectors) {
|
||||
connectorDAO.save(connector);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Connector> getConnectors() {
|
||||
return Collections.unmodifiableList(connectors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connector getConnectorByMajorId(String majorId) {
|
||||
if (majorId == null || connectors == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Connector connector : connectors) {
|
||||
if (connector.getMajorId().equals(majorId)) {
|
||||
return connector;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<AppProperties>> getAppProperties() {
|
||||
return appPropertiesMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAppConnectorId(String connectorId) {
|
||||
this.connectorId = connectorId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppConnectorId() {
|
||||
return connectorId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AppProperties> getAllAppPropertiesByMajorId(
|
||||
String majorConnectorId) {
|
||||
if (appPropertiesMap == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return appPropertiesMap.get(majorConnectorId);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,10 @@
|
|||
package org.libreplan.web.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||
import org.libreplan.business.common.entities.AppProperties;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
import org.libreplan.business.common.entities.EntityNameEnum;
|
||||
import org.libreplan.business.common.entities.EntitySequence;
|
||||
import org.libreplan.business.common.entities.JiraConfiguration;
|
||||
|
|
@ -196,12 +195,8 @@ public interface IConfigurationModel {
|
|||
|
||||
void setJiraConnectorTypeOfWorkHours(TypeOfWorkHours typeOfWorkHours);
|
||||
|
||||
Map<String, List<AppProperties>> getAppProperties();
|
||||
List<Connector> getConnectors();
|
||||
|
||||
void setAppConnectorId(String connectorId);
|
||||
|
||||
String getAppConnectorId();
|
||||
|
||||
List<AppProperties> getAllAppPropertiesByMajorId(String majorConnectorId);
|
||||
Connector getConnectorByMajorId(String majorId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,10 @@ package org.libreplan.web.orders;
|
|||
import static org.libreplan.web.I18nHelper._;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.libreplan.business.common.daos.IAppPropertiesDAO;
|
||||
import org.libreplan.business.common.entities.AppProperties;
|
||||
import org.libreplan.business.common.daos.IConnectorDAO;
|
||||
import org.libreplan.business.common.entities.Connector;
|
||||
import org.libreplan.business.common.entities.PredefinedConnectorProperties;
|
||||
import org.libreplan.business.common.entities.PredefinedConnectors;
|
||||
import org.libreplan.business.orders.entities.OrderSyncInfo;
|
||||
import org.libreplan.importers.IExportTimesheetsToTim;
|
||||
import org.libreplan.web.common.IMessagesForUser;
|
||||
|
|
@ -55,7 +57,7 @@ public class TimSynchronizationController extends GenericForwardComposer {
|
|||
private IExportTimesheetsToTim exportTimesheetsToTim;
|
||||
|
||||
@Autowired
|
||||
private IAppPropertiesDAO appPropertiesDAO;
|
||||
private IConnectorDAO connectorDAO;
|
||||
|
||||
private Component messagesContainer;
|
||||
|
||||
|
|
@ -101,8 +103,13 @@ public class TimSynchronizationController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
public boolean isTimActivated() {
|
||||
AppProperties appProperties = appPropertiesDAO.findByMajorIdAndName(
|
||||
"Tim", "Activated");
|
||||
return appProperties.getPropertyValue().equalsIgnoreCase("Y");
|
||||
Connector connector = connectorDAO
|
||||
.findUniqueByMajorId(PredefinedConnectors.TIM.getMajorId());
|
||||
if (connector == null) {
|
||||
return false;
|
||||
}
|
||||
return connector.getPropertiesAsMap()
|
||||
.get(PredefinedConnectorProperties.ACTIVATED)
|
||||
.equalsIgnoreCase("Y");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -462,18 +462,18 @@
|
|||
<hbox pack="center">
|
||||
<label value="${i18n:_('Select connector')}" />
|
||||
<combobox id="connectorCombo" autodrop="true"
|
||||
model="@{configurationController.appPropertyConnectors}"
|
||||
model="@{configurationController.connectors}"
|
||||
selectedItem="@{configurationController.selectedConnector}">
|
||||
<comboitem
|
||||
self="@{each=appPropertyConnectors}"
|
||||
label="@{appPropertyConnectors}"
|
||||
value="@{appPropertyConnectors}" />
|
||||
self="@{each=connectors}"
|
||||
label="@{connectors.majorId}"
|
||||
value="@{connectors}" />
|
||||
</combobox>
|
||||
</hbox>
|
||||
<separator />
|
||||
<grid id="appPropertriesGrid"
|
||||
model="@{configurationController.appPropertries}"
|
||||
rowRenderer="@{configurationController.appPropertriesRenderer}">
|
||||
<grid id="connectorPropertriesGrid"
|
||||
model="@{configurationController.connectorPropertries}"
|
||||
rowRenderer="@{configurationController.connectorPropertriesRenderer}">
|
||||
<columns>
|
||||
<column label="${i18n:_('Name')}" width="200px"/>
|
||||
<column label="${i18n:_('Value')}" />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue