diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/Registry.java b/libreplan-business/src/main/java/org/libreplan/business/common/Registry.java index 82cbf840f..bcbe9dafa 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/Registry.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/Registry.java @@ -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; + } + } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/daos/AppPropertiesDAO.java b/libreplan-business/src/main/java/org/libreplan/business/common/daos/ConnectorDAO.java similarity index 55% rename from libreplan-business/src/main/java/org/libreplan/business/common/daos/AppPropertiesDAO.java rename to libreplan-business/src/main/java/org/libreplan/business/common/daos/ConnectorDAO.java index f97c41292..90e055384 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/daos/AppPropertiesDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/daos/ConnectorDAO.java @@ -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 + * @author Manuel Rego Casasnovas */ @Repository @Scope(BeanDefinition.SCOPE_SINGLETON) -public class AppPropertiesDAO extends GenericDAOHibernate - implements IAppPropertiesDAO { +public class ConnectorDAO extends GenericDAOHibernate + implements IConnectorDAO { @Override @Transactional(readOnly = true) - public List getAll() { - return list(AppProperties.class); + public List getAll() { + return list(Connector.class); } @Override @Transactional(readOnly = true) - @SuppressWarnings("unchecked") - public Map 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 list = c.list(); - - Map map = new HashMap(); - 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); } } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/daos/IAppPropertiesDAO.java b/libreplan-business/src/main/java/org/libreplan/business/common/daos/IConnectorDAO.java similarity index 68% rename from libreplan-business/src/main/java/org/libreplan/business/common/daos/IAppPropertiesDAO.java rename to libreplan-business/src/main/java/org/libreplan/business/common/daos/IConnectorDAO.java index 862d73a6a..5e818970c 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/daos/IAppPropertiesDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/daos/IConnectorDAO.java @@ -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 + * @author Manuel Rego Casasnovas */ -public interface IAppPropertiesDAO extends IGenericDAO { +public interface IConnectorDAO extends IGenericDAO { - List getAll(); + List getAll(); - Map findByMajorId(String majorId); + Connector findUniqueByMajorId(String majorId); - AppProperties findByMajorIdAndName(String majorId, String proprtyName); + boolean existsByNameAnotherTransaction(Connector connector); + + Connector findUniqueByMajorIdAnotherTransaction(String majorId); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/AppProperties.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/AppProperties.java deleted file mode 100644 index 7c048051f..000000000 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/AppProperties.java +++ /dev/null @@ -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 . - */ - -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: - *
    - *
  • majorId: an indication for some large piece of functionality like "jira" - * for "jira-connector"
  • - *
  • minorId: used for sub module within this majorId. It can be null if not - * used
  • - *
  • propertyName: holder for the name of a property
  • - *
  • propertyValue: holder for the value of a property
  • - *
- * - * @author Miciele Ghiorghis - */ -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; - } -} diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Connector.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Connector.java new file mode 100644 index 000000000..b1aca7e85 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Connector.java @@ -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 . + */ + +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 majorId 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 + * @author Manuel Rego Casasnovas + */ +public class Connector extends BaseEntity { + + public static Connector create(String majorId) { + return create(new Connector(majorId)); + } + + private String majorId; + + private List properties = new ArrayList(); + + /** + * 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 getProperties() { + return Collections.unmodifiableList(properties); + } + + public void setProperties(List properties) { + this.properties = properties; + } + + public void addProperty(ConnectorProperty property) { + properties.add(property); + } + + public Map getPropertiesAsMap() { + Map map = new HashMap(); + 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()); + } + + } + +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/ConnectorBootstrap.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/ConnectorBootstrap.java new file mode 100644 index 000000000..90a693d84 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/ConnectorBootstrap.java @@ -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 . + */ + +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 + */ +@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); + } + } + } + +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/ConnectorProperty.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/ConnectorProperty.java new file mode 100644 index 000000000..7cb6b79d7 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/ConnectorProperty.java @@ -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 . + */ + +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 + */ +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; + } + +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/IConnectorBootstrap.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/IConnectorBootstrap.java new file mode 100644 index 000000000..d70373b32 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/IConnectorBootstrap.java @@ -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 . + */ + +package org.libreplan.business.common.entities; + +import org.libreplan.business.IDataBootstrap; + +/** + * Contract for {@link ConnectorBootstrap}. + * + * @author Manuel Rego Casasnovas + */ +public interface IConnectorBootstrap extends IDataBootstrap { + + void loadRequiredData(); + +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java new file mode 100644 index 000000000..400cceb9e --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectorProperties.java @@ -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 . + */ + +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 + * @author Manuel Rego Casasnovas + */ +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"); + +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java new file mode 100644 index 000000000..a7a3cd6ea --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/PredefinedConnectors.java @@ -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 . + */ + +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 + * @author Manuel Rego Casasnovas + */ +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 properties; + + private PredefinedConnectors(String majorId, + ConnectorProperty... properties) { + this.majorId = majorId; + this.properties = Arrays.asList(properties); + } + + public String getMajorId() { + return majorId; + } + + public List getProperties() { + return properties; + } + +} diff --git a/libreplan-business/src/main/resources/db.changelog-1.3.xml b/libreplan-business/src/main/resources/db.changelog-1.3.xml index 1aad14a67..24677cb41 100644 --- a/libreplan-business/src/main/resources/db.changelog-1.3.xml +++ b/libreplan-business/src/main/resources/db.changelog-1.3.xml @@ -334,65 +334,51 @@ baseTableName="order_sync_info" baseColumnNames="order_element_id" referencedTableName="order_table" referencedColumnNames="order_element_id" /> - - - Create new table app_properties - + + + + Create tables related to Connector entity + - + - + - - - - - + + + + + + + + + + + + + + + + + - - Insert some default keys and values - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Create new table job_scheduler_configuration diff --git a/libreplan-business/src/main/resources/libreplan-business-spring-config.xml b/libreplan-business/src/main/resources/libreplan-business-spring-config.xml index beebed0c0..e5e183a1b 100644 --- a/libreplan-business/src/main/resources/libreplan-business-spring-config.xml +++ b/libreplan-business/src/main/resources/libreplan-business-spring-config.xml @@ -91,7 +91,7 @@ org/libreplan/business/expensesheets/entities/ExpenseSheets.hbm.xml - org/libreplan/business/common/entities/AppProperties.hbm.xml + org/libreplan/business/common/entities/Connector.hbm.xml org/libreplan/business/common/entities/JobSchedulerConfiguration.hbm.xml diff --git a/libreplan-business/src/main/resources/org/libreplan/business/common/entities/AppProperties.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Connector.hbm.xml similarity index 57% rename from libreplan-business/src/main/resources/org/libreplan/business/common/entities/AppProperties.hbm.xml rename to libreplan-business/src/main/resources/org/libreplan/business/common/entities/Connector.hbm.xml index 789b78d0f..fd9f70543 100644 --- a/libreplan-business/src/main/resources/org/libreplan/business/common/entities/AppProperties.hbm.xml +++ b/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Connector.hbm.xml @@ -3,7 +3,7 @@ - + 100 @@ -13,9 +13,18 @@ - - - + + + + + + + + + + + diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/ExportTimesheetsToTim.java b/libreplan-webapp/src/main/java/org/libreplan/importers/ExportTimesheetsToTim.java index 372bee52b..1eda4acba 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/ExportTimesheetsToTim.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/ExportTimesheetsToTim.java @@ -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 prop = appPropertiesDAO - .findByMajorId(CONNECTOR_MAJOR_ID); + String majorId = PredefinedConnectors.TIM.getMajorId(); + Connector connector = connectorDAO.findUniqueByMajorId(majorId); + if (connector == null) { + return; + } + List 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 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 appProperties) { + Connector connector) { + Map 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()); } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/IExportTimesheetsToTim.java b/libreplan-webapp/src/main/java/org/libreplan/importers/IExportTimesheetsToTim.java index d3b0164d6..7a8645384 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/IExportTimesheetsToTim.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/IExportTimesheetsToTim.java @@ -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 - * NrDaysTimesheetToTim specified in configuration entity - * {@link AppProperties} and the current-date + * NrDaysTimesheetToTim specified in the Tim {@link Connector} and + * the current-date * * @author Miciele Ghiorghis */ diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/IImportRosterFromTim.java b/libreplan-webapp/src/main/java/org/libreplan/importers/IImportRosterFromTim.java index a5abbfab9..a7f500f1f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/IImportRosterFromTim.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/IImportRosterFromTim.java @@ -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 - * NrDaysRosterFromTim specified in configuration entity - * {@link AppProperties} + * NrDaysRosterFromTim specified in Tim {@link Connector}. * * @author Miciele Ghiorghis */ diff --git a/libreplan-webapp/src/main/java/org/libreplan/importers/ImportRosterFromTim.java b/libreplan-webapp/src/main/java/org/libreplan/importers/ImportRosterFromTim.java index 89c0f36d8..f294bef6a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/importers/ImportRosterFromTim.java +++ b/libreplan-webapp/src/main/java/org/libreplan/importers/ImportRosterFromTim.java @@ -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 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 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"); diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java index b2d26110e..6dd6f3118 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java @@ -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 appProperties = getAppProperties(connectorId); - String url = appProperties.get("Server"); - String username = appProperties.get("Username"); - String password = appProperties.get("Password"); - if (connectorId.equals("Tim")) { + Map 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 getAppProperties(String majorConnectorId) { - List appProperties = configurationModel - .getAllAppPropertiesByMajorId(majorConnectorId); - Map map = new HashMap(); - for (AppProperties appProp : appProperties) { - map.put(appProp.getPropertyName(), appProp.getPropertyValue()); - } - return map; - } - private boolean checkValidEntitySequenceRows() { Rows rows = entitySequencesGrid.getRows(); for (Row row : (List) 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 getConnectors() { + return configurationModel.getConnectors(); } - public Set getAppPropertyConnectors() { - return getAllAppProperties().keySet(); + public Connector getSelectedConnector() { + return selectedConnector; } - private Map> 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 getAppPropertries() { - String appConnectorId = configurationModel.getAppConnectorId(); - if (StringUtils.isEmpty(appConnectorId)) { + public List 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() { @Override public String get() { - return appProperties.getPropertyValue(); + return property.getValue(); } }, new Util.Setter() { @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")); diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java index 458ae63cd..0152ef561 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java @@ -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 currencies = getAllCurrencies(); + private List connectors; + @Autowired private IConfigurationDAO configurationDAO; @@ -92,11 +94,7 @@ public class ConfigurationModel implements IConfigurationModel { private IWorkReportDAO workReportDAO; @Autowired - IAppPropertiesDAO appPropertiesDAO; - - private Map> appPropertiesMap = new HashMap>(); - - 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()); - } - 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 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> getAppProperties() { - return appPropertiesMap; - } - - @Override - public void setAppConnectorId(String connectorId) { - this.connectorId = connectorId; - } - - @Override - public String getAppConnectorId() { - return connectorId; - } - - @Override - public List getAllAppPropertiesByMajorId( - String majorConnectorId) { - if (appPropertiesMap == null) { - return Collections.emptyList(); - } - return appPropertiesMap.get(majorConnectorId); + return null; } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java index 735d579d1..639f27fa4 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java @@ -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> getAppProperties(); + List getConnectors(); - void setAppConnectorId(String connectorId); - - String getAppConnectorId(); - - List getAllAppPropertiesByMajorId(String majorConnectorId); + Connector getConnectorByMajorId(String majorId); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/orders/TimSynchronizationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/orders/TimSynchronizationController.java index 14ee91290..9458ca87d 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/orders/TimSynchronizationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/orders/TimSynchronizationController.java @@ -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"); } } diff --git a/libreplan-webapp/src/main/webapp/common/configuration.zul b/libreplan-webapp/src/main/webapp/common/configuration.zul index 2084feb00..6410b2d4a 100644 --- a/libreplan-webapp/src/main/webapp/common/configuration.zul +++ b/libreplan-webapp/src/main/webapp/common/configuration.zul @@ -462,18 +462,18 @@ - +