use of org.apache.commons.collections.map.HashedMap in project tdi-studio-se by Talend.
the class UpdateNodeParameterCommand method updateProperty.
@SuppressWarnings("unchecked")
private void updateProperty() {
Object updateObject = result.getUpdateObject();
if (updateObject == null) {
return;
}
if (updateObject instanceof Node) {
// opened job
Node node = (Node) updateObject;
boolean update = false;
// added by wzhang for bug 9302
boolean isXsdPath = false;
Object parameter = result.getParameter();
IElementParameter curPropertyParam = null;
//$NON-NLS-1$
String parentParamName = "PROPERTY";
ConnectionItem connectionItem = null;
if (parameter instanceof ConnectionItem) {
if (parameter instanceof XmlFileConnectionItem) {
String filePath = ((XmlFileConnection) ((XmlFileConnectionItem) parameter).getConnection()).getXmlFilePath();
if (filePath != null) {
if (XmlUtil.isXSDFile(filePath)) {
isXsdPath = true;
}
}
}
connectionItem = (ConnectionItem) result.getParameter();
for (IElementParameter param : node.getElementParameters()) {
if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE && param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue().equals(connectionItem.getProperty().getId())) {
curPropertyParam = param;
parentParamName = curPropertyParam.getName();
if (connectionItem != null) {
ConnectionContextHelper.addContextForNodeParameter(node, connectionItem, false);
}
break;
}
}
}
if (result.getResultType() == EUpdateResult.UPDATE) {
// upgrade from repository
if (result.isChecked() && connectionItem != null) {
List<? extends IElementParameter> elemParameters = new ArrayList<>(node.getElementParameters());
for (IElementParameter param : elemParameters) {
String repositoryValue = param.getRepositoryValue();
if (param.getRepositoryValue() == null || (curPropertyParam != null && param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(curPropertyParam.getName()))) {
continue;
}
if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
continue;
}
if ((repositoryValue != null) && (param.isShow(node.getElementParameters()) || node.getComponentProperties() != null || (node instanceof INode && ((INode) node).getComponent().getName().equals("tAdvancedFileOutputXML")) || (node instanceof INode && ((INode) node).getComponent().getName().equals("tESBProviderRequest")))) {
//$NON-NLS-1$
if (param.getName().equals(EParameterName.PROPERTY_TYPE.getName()) || param.getFieldType() == EParameterFieldType.MEMO_SQL) {
continue;
}
if (param.getFieldType().equals(EParameterFieldType.FILE) && isXsdPath) {
continue;
}
IMetadataTable table = null;
if (!node.getMetadataList().isEmpty()) {
table = node.getMetadataList().get(0);
}
Object objectValue = RepositoryToComponentProperty.getValue(connectionItem.getConnection(), repositoryValue, table);
if (objectValue == null || "".equals(objectValue)) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
if (service != null) {
String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (node.getComponent().getName().startsWith("tESB")) {
if (propertyValue.contains(" - ")) {
propertyValue = propertyValue.split(" - ")[0];
}
}
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
if (lastVersion != null) {
Item item = lastVersion.getProperty().getItem();
if (item != null) {
Object objectValueFromESB = service.getValue(item, repositoryValue, node);
if (objectValueFromESB != null) {
objectValue = objectValueFromESB;
}
}
}
}
}
}
if (param.getName().equals(EParameterName.CDC_TYPE_MODE.getName())) {
//
String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
Item item = null;
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
if (lastVersion != null) {
item = lastVersion.getProperty().getItem();
}
if (item != null && PluginChecker.isCDCPluginLoaded()) {
ICDCProviderService service = (ICDCProviderService) GlobalServiceRegister.getDefault().getService(ICDCProviderService.class);
if (service != null) {
try {
List<IRepositoryViewObject> all;
all = CorePlugin.getDefault().getProxyRepositoryFactory().getAll(ERepositoryObjectType.METADATA_CONNECTIONS);
for (IRepositoryViewObject obj : all) {
Item tempItem = obj.getProperty().getItem();
if (tempItem instanceof DatabaseConnectionItem) {
String cdcLinkId = service.getCDCConnectionLinkId((DatabaseConnectionItem) tempItem);
if (cdcLinkId != null && item.getProperty().getId().equals(cdcLinkId)) {
objectValue = RepositoryToComponentProperty.getValue(((DatabaseConnectionItem) tempItem).getConnection(), repositoryValue, node.getMetadataList().get(0));
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(IJsonFileService.class)) {
IJsonFileService jsonService = (IJsonFileService) GlobalServiceRegister.getDefault().getService(IJsonFileService.class);
boolean paramChanged = jsonService.changeFilePathFromRepository(connectionItem.getConnection(), param, node, objectValue);
if (paramChanged) {
continue;
}
}
if (objectValue != null) {
if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && repositoryValue.equals(UpdatesConstants.TYPE)) {
boolean found = false;
String[] items = param.getListRepositoryItems();
for (int i = 0; (i < items.length) && (!found); i++) {
if (objectValue.equals(items[i])) {
found = true;
node.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
}
}
} else {
// update tFileInputExcel job
if (param.getFieldType().equals(EParameterFieldType.TABLE)) {
String name = param.getName();
if (name.equals("ROOT") || name.equals("LOOP") || name.equals("GROUP") && objectValue instanceof List) {
param.setValue(objectValue);
} else if (param.getName().equals("SHEETLIST") && objectValue instanceof List) {
List<Map<String, Object>> paramMaps = (List<Map<String, Object>>) param.getValue();
if (paramMaps == null) {
paramMaps = new ArrayList<Map<String, Object>>();
node.setPropertyValue(param.getName(), paramMaps);
} else {
// hywang add for 9537
List<Map<String, Object>> objectValueList = (List<Map<String, Object>>) objectValue;
if (paramMaps.size() < objectValueList.size()) {
paramMaps.clear();
for (int i = 0; i < objectValueList.size(); i++) {
Map<String, Object> map = objectValueList.get(i);
paramMaps.add(map);
}
} else {
String value = null;
List<String> repNames = new ArrayList<String>();
for (int i = 0; i < objectValueList.size(); i++) {
repNames.add(objectValueList.get(i).get("SHEETNAME").toString());
}
for (int j = 0; j < paramMaps.size(); j++) {
Map<String, Object> map = paramMaps.get(j);
value = map.get("SHEETNAME").toString();
if (!repNames.contains(value)) {
paramMaps.remove(j);
}
}
}
}
} else if ((name.equals("HADOOP_ADVANCED_PROPERTIES") || name.equals("ADVANCED_PROPERTIES") || name.equals("HBASE_PARAMETERS") || name.equals("SAP_PROPERTIES") && objectValue instanceof List)) {
List<HashMap<String, Object>> oldValue = (List<HashMap<String, Object>>) param.getValue();
for (HashMap<String, Object> map : oldValue) {
if (map.get("BUILDIN") != null && !map.get("BUILDIN").equals("") && Boolean.valueOf(String.valueOf(map.get("BUILDIN")))) {
((List<HashMap<String, Object>>) objectValue).add(map);
}
}
param.setValue(objectValue);
} else // it in jobs
if (param.getName().equals("DRIVER_JAR") && objectValue instanceof List) {
param.setValue(objectValue);
}
} else {
node.setPropertyValue(param.getName(), objectValue);
}
}
} else if (param.getFieldType().equals(EParameterFieldType.TABLE) && UpdatesConstants.XML_MAPPING.equals(repositoryValue)) {
RepositoryToComponentProperty.getTableXMLMappingValue(connectionItem.getConnection(), (List<Map<String, Object>>) param.getValue(), node);
} else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getName().equals("PARAMS")) {
objectValue = RepositoryToComponentProperty.getValue(connectionItem.getConnection(), "PARAMS", node.getMetadataList().get(0));
List<Map<String, Object>> paramMaps = (List<Map<String, Object>>) param.getValue();
if (paramMaps == null) {
paramMaps = new ArrayList<Map<String, Object>>();
} else {
paramMaps.clear();
}
if (objectValue != null) {
List<String> objectValueList = (List<String>) objectValue;
for (int i = 0; i < objectValueList.size(); i++) {
Map<String, Object> map = new HashedMap();
map.put("VALUE", TalendTextUtils.addQuotes(objectValueList.get(i)));
paramMaps.add(map);
}
}
} else if (node.getComponentProperties() != null && objectValue == null) {
// for new framework, still save the null value in component
node.setPropertyValue(param.getName(), objectValue);
}
if (!("tMDMReceive".equals(node.getComponent().getName()) && "XPATH_PREFIX".equals(//$NON-NLS-1$ //$NON-NLS-2$
param.getRepositoryValue()))) {
param.setRepositoryValueUsed(true);
param.setReadOnly(true);
update = true;
}
}
}
} else {
// Added TDQ-11688 20170309 yyin
ITDQPatternService service = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQPatternService.class)) {
service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
}
if (service != null && (service.isSinglePatternNode(node) || service.isMultiPatternNode(node)) && parameter != null && parameter instanceof IElementParameter) {
IElementParameter elementParameter = node.getElementParameter(((IElementParameter) parameter).getName());
if (elementParameter != null && !elementParameter.getValue().equals(((IElementParameter) parameter).getValue())) {
elementParameter.setValue(((IElementParameter) parameter).getValue());
}
update = true;
Object regexValue = null;
Object parameterValue = ((IElementParameter) parameter).getValue();
if ("PATTERN_REGEX".equals(((IElementParameter) parameter).getName())) {
regexValue = parameterValue;
} else if ("SCHEMA_PATTERN_CHECK".equals(((IElementParameter) parameter).getName())) {
List<Map<String, String>> multiPatternList = ((List<Map<String, String>>) parameterValue);
for (Map<String, String> patternMap : multiPatternList) {
regexValue = patternMap.get("PATTERN_REGEX");
if (regexValue == null) {
patternMap.put("PATTERN_PROPERTY", EmfComponent.BUILTIN);
}
}
}
if (regexValue == null || regexValue.toString().isEmpty()) {
update = false;
}
}
}
}
if (!update) {
// bult-in
String propertyName = parentParamName + ":" + EParameterName.PROPERTY_TYPE.getName();
if (this.result.getParameter() instanceof IElementParameter) {
IElementParameter parentParam = ((IElementParameter) this.result.getParameter()).getParentParameter();
if (parentParam != null) {
parentParamName = parentParam.getName();
propertyName = parentParam.getName() + ":" + parentParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getName();
}
}
node.setPropertyValue(propertyName, EmfComponent.BUILTIN);
for (IElementParameter param : node.getElementParameters()) {
if (param.getRepositoryValue() == null || param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(parentParamName)) {
continue;
}
if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
continue;
}
if (param.isShow(node.getElementParameters())) {
if (param.getName().equals(EParameterName.PROPERTY_TYPE.getName()) || param.getFieldType() == EParameterFieldType.MEMO_SQL) {
continue;
}
param.setRepositoryValueUsed(false);
param.setReadOnly(false);
}
}
}
}
}
use of org.apache.commons.collections.map.HashedMap in project gocd by gocd.
the class AuthorizationMessageConverterV1 method getRoleConfigs.
private List<Map<String, Object>> getRoleConfigs(List<PluginRoleConfig> roleConfigs) {
List<Map<String, Object>> configs = new ArrayList<>();
if (roleConfigs == null) {
return configs;
}
for (PluginRoleConfig roleConfig : roleConfigs) {
Map<String, Object> config = new HashedMap();
config.put("name", roleConfig.getName().toString());
config.put("auth_config_id", roleConfig.getAuthConfigId());
config.put("configuration", roleConfig.getConfigurationAsMap(true));
configs.add(config);
}
return configs;
}
use of org.apache.commons.collections.map.HashedMap in project Gargoyle by callakrsos.
the class CachedMapTest method miltiThread2.
@Test
public void miltiThread2() throws InterruptedException {
CachedMap<Object, Object> cachedMap = new CachedMap<>(1000);
for (int i = 0; i < 10; i++) {
final int inn = i;
Thread thread = new Thread(() -> {
String name = Thread.currentThread().getName();
// cachedMap.put(name, "zz" + inn);
cachedMap.put(name, "zz" + inn);
cachedMap.put(name, "zz" + inn);
cachedMap.put(name, "zz" + inn);
cachedMap.put(name, "zz" + inn);
cachedMap.put(name, "zz" + inn);
System.out.println(name + " " + cachedMap.get(name));
try {
Thread.sleep(1500);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println(name + " " + cachedMap.get(name));
HashedMap hashedMap = new HashedMap();
hashedMap.put(name, "zz" + inn);
cachedMap.putAll(hashedMap);
System.out.println(name + " " + cachedMap);
try {
Thread.sleep(1500);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(name + " " + cachedMap);
}, "Name" + i);
thread.start();
}
System.out.println(cachedMap.isEmpty());
Thread.currentThread().sleep(5000);
System.out.println(cachedMap.isEmpty());
}
use of org.apache.commons.collections.map.HashedMap in project herddb by diennea.
the class Transaction method registerLockOnTable.
public void registerLockOnTable(String tableName, LockHandle handle) {
HashedMap ll = locks.get(tableName);
if (ll == null) {
ll = new HashedMap();
locks.put(tableName, ll);
}
ll.put(handle.key, handle);
}
use of org.apache.commons.collections.map.HashedMap in project carbon-business-process by wso2.
the class UserSubstitutionService method querySubstitutes.
/**
* Query the substitution records based on substitute, assignee and enabled or disabled.
* Pagination parameters, start, size, sort, order are allowed.
* @return paginated list of substitution info records
*/
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response querySubstitutes() {
if (!subsFeatureEnabled) {
return Response.status(405).build();
}
Map<String, String> queryMap = new HashedMap();
for (Map.Entry<String, String> entry : propertiesMap.entrySet()) {
String value = uriInfo.getQueryParameters().getFirst(entry.getKey());
if (value != null) {
queryMap.put(entry.getValue(), value);
}
}
// validate the parameters
try {
// replace with tenant aware user names
String tenantAwareUser = getTenantAwareUser(queryMap.get(SubstitutionQueryProperties.USER));
queryMap.put(SubstitutionQueryProperties.USER, tenantAwareUser);
String tenantAwareSub = getTenantAwareUser(queryMap.get(SubstitutionQueryProperties.SUBSTITUTE));
queryMap.put(SubstitutionQueryProperties.SUBSTITUTE, tenantAwareSub);
if (!isUserAuthorizedForSubstitute(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername())) {
String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (!((queryMap.get(SubstitutionQueryProperties.USER) != null && queryMap.get(SubstitutionQueryProperties.USER).equals(loggedInUser)) || (queryMap.get(SubstitutionQueryProperties.SUBSTITUTE) != null && queryMap.get(SubstitutionQueryProperties.SUBSTITUTE).equals(loggedInUser)))) {
throw new BPMNForbiddenException("Not allowed to view others substitution details. No sufficient permission");
}
}
} catch (UserStoreException e) {
throw new ActivitiException("Error accessing User Store for input validations", e);
}
// validate pagination parameters
validatePaginationParams(queryMap);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<SubstitutesDataModel> dataModelList = UserSubstitutionUtils.querySubstitutions(queryMap, tenantId);
int totalResultCount = UserSubstitutionUtils.getQueryResultCount(queryMap, tenantId);
SubstituteInfoCollectionResponse collectionResponse = new SubstituteInfoCollectionResponse();
collectionResponse.setTotal(totalResultCount);
List<SubstituteInfoResponse> responseList = new ArrayList<>();
for (SubstitutesDataModel subsData : dataModelList) {
SubstituteInfoResponse response = new SubstituteInfoResponse();
response.setEnabled(subsData.isEnabled());
response.setEndTime(subsData.getSubstitutionEnd());
response.setStartTime(subsData.getSubstitutionStart());
response.setSubstitute(subsData.getSubstitute());
response.setAssignee(subsData.getUser());
responseList.add(response);
}
collectionResponse.setSubstituteInfoList(responseList);
collectionResponse.setSize(responseList.size());
String sortType = getSortType(queryMap.get(SubstitutionQueryProperties.SORT));
collectionResponse.setSort(sortType);
collectionResponse.setStart(Integer.parseInt(queryMap.get(SubstitutionQueryProperties.START)));
collectionResponse.setOrder(queryMap.get(SubstitutionQueryProperties.ORDER));
return Response.ok(collectionResponse).build();
}
Aggregations