Skip to content

Commit

Permalink
tim-connector: Created new entity Connector based on AppProperties
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrego committed Feb 27, 2013
1 parent 4aae863 commit c29015e
Show file tree
Hide file tree
Showing 22 changed files with 641 additions and 342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -203,6 +204,9 @@ public class Registry {
@Autowired
private IOrderAuthorizationDAO orderAuthorizationDAO;

@Autowired
private IConnectorDAO connectorDAO;

@Autowired
private IAdHocTransactionService transactionServiceDAO;

Expand Down Expand Up @@ -379,4 +383,8 @@ public static IOrderAuthorizationDAO getOrderAuthorizationDAO() {
return getInstance().orderAuthorizationDAO;
}

public static IConnectorDAO getConnectorDAO() {
return getInstance().connectorDAO;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
return (Connector) c.uniqueResult();
}

Map<String, String> map = new HashMap<String, String>();
for (AppProperties appProperty : list) {
map.put(appProperty.getPropertyName(),
appProperty.getPropertyValue());
}
return map;
@Override
@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)
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 Connector findUniqueByMajorIdAnotherTransaction(String majorId) {
return findUniqueByMajorId(majorId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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());
}

}

}
Loading

0 comments on commit c29015e

Please sign in to comment.