-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
22 changed files
with
641 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 0 additions & 95 deletions
95
libreplan-business/src/main/java/org/libreplan/business/common/entities/AppProperties.java
This file was deleted.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
libreplan-business/src/main/java/org/libreplan/business/common/entities/Connector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.