use of org.talend.camel.core.model.camelProperties.BeanItem in project tesb-studio-se by Talend.
the class UpdateBeansDefaultLibrariesMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof BeanItem) {
if (camelVersion == null) {
IComponent component = ComponentsFactoryProvider.getInstance().get("cTimer", "CAMEL");
for (ModuleNeeded mn : component.getModulesNeeded()) {
MavenArtifact ma = MavenUrlHelper.parseMvnUrl(mn.getMavenUri());
if (ma != null) {
if (StringUtils.equals(camelPrefix, ma.getArtifactId() + "-")) {
camelVersionSubString = mn.getModuleName().substring(camelPrefix.length());
camelVersion = ma.getVersion();
break;
}
} else {
if (mn.getModuleName().startsWith(camelPrefix)) {
camelVersionSubString = mn.getModuleName().substring(camelPrefix.length());
camelVersion = camelVersionSubString.substring(0, camelVersionSubString.lastIndexOf(".jar"));
break;
}
}
}
}
BeanItem beanItem = (BeanItem) item;
addModulesNeededForBeans(beanItem);
try {
ProxyRepositoryFactory.getInstance().save(beanItem);
generateReportRecord(new MigrationReportRecorder(this, item, "Set of default Bean dependencies is updated"));
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
} else {
return ExecutionResult.NOTHING_TO_DO;
}
}
use of org.talend.camel.core.model.camelProperties.BeanItem in project tesb-studio-se by Talend.
the class UpdateBeansPackageReplaceMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
ExecutionResult execResult = ExecutionResult.NOTHING_TO_DO;
String pattern = "(\\s*|\t|\r|\n)";
if (item instanceof RoutineItem) {
boolean isItemUpdated = false;
RoutineItem resourceItem = null;
if (item instanceof BeanItem) {
resourceItem = (BeanItem) item;
} else {
resourceItem = (RoutineItem) item;
}
String content = new String(resourceItem.getContent().getInnerContent());
Set<Entry<Object, Object>> entrySet = PACKAGES_TO_REPLACE.entrySet();
for (Entry<Object, Object> entry : entrySet) {
String prePeplaceValue = (String) entry.getKey();
String replaceValue = (String) entry.getValue();
StringBuffer computePattenBuffer = new StringBuffer();
String[] computePattenArray = prePeplaceValue.split("\\.");
for (int i = 0; i < computePattenArray.length; i++) {
computePattenBuffer.append(pattern).append(computePattenArray[i]).append(pattern);
if (i != computePattenArray.length - 1) {
computePattenBuffer.append(".");
}
}
Pattern p = Pattern.compile(computePattenBuffer.toString());
Matcher m = p.matcher(content);
if (m.find()) {
content = content.replaceAll(computePattenBuffer.toString(), " " + replaceValue + " ");
resourceItem.getContent().setInnerContent(content.getBytes());
isItemUpdated = true;
}
}
resourceItem.getProperty().getInformations().clear();
if (isItemUpdated) {
try {
ProxyRepositoryFactory.getInstance().save(resourceItem);
execResult = ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
log.error("Error replacing import statements", e);
ExceptionHandler.process(e);
execResult = ExecutionResult.FAILURE;
} catch (Exception e) {
log.error("Building Code Project Failed", e);
ExceptionHandler.process(e);
execResult = ExecutionResult.FAILURE;
}
}
}
return execResult;
}
use of org.talend.camel.core.model.camelProperties.BeanItem in project tesb-studio-se by Talend.
the class UpdateBeansLibrariesMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof BeanItem) {
if (camelVersion == null) {
IComponent component = ComponentsFactoryProvider.getInstance().get("cTimer", "CAMEL");
for (ModuleNeeded mn : component.getModulesNeeded()) {
if (mn.getModuleName().startsWith(camelPrefix)) {
String moduleName = mn.getModuleName();
camelVersion = moduleName.substring(moduleName.lastIndexOf("-") + 1, moduleName.lastIndexOf("."));
break;
}
}
}
BeanItem beanItem = (BeanItem) item;
upgradeModulesNeededForBeans(beanItem);
try {
ProxyRepositoryFactory.getInstance().save(beanItem);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
} else {
return ExecutionResult.NOTHING_TO_DO;
}
}
use of org.talend.camel.core.model.camelProperties.BeanItem in project tesb-studio-se by Talend.
the class AddBeansDefaultLibrariesMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof BeanItem) {
BeanItem beanItem = (BeanItem) item;
addModulesNeededForBeans(beanItem);
try {
ProxyRepositoryFactory.getInstance().save(beanItem);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
} else {
return ExecutionResult.NOTHING_TO_DO;
}
}
use of org.talend.camel.core.model.camelProperties.BeanItem in project tesb-studio-se by Talend.
the class CamelRepositoryContentHandlerTest method testCreateNewItem.
/**
* Test method for
* {@link org.talend.camel.designer.CamelRepositoryContentHandler#createNewItem(org.talend.core.model.repository.ERepositoryObjectType)}
* .
*/
@Test
public void testCreateNewItem() {
CamelRepositoryContentHandler handler = new CamelRepositoryContentHandler();
Assert.assertTrue(handler.createNewItem(ERepositoryObjectType.PROCESS_ROUTE) instanceof CamelProcessItem);
Assert.assertTrue(handler.createNewItem(ERepositoryObjectType.RESOURCES) instanceof RouteResourceItem);
Assert.assertTrue(handler.createNewItem(ERepositoryObjectType.valueOf(ERepositoryObjectType.class, "BEANS")) instanceof BeanItem);
Assert.assertNull(handler.createNewItem(ERepositoryObjectType.valueOf(ERepositoryObjectType.class, "ROUTE_RESOURCES")));
Assert.assertTrue(handler.createNewItem(ERepositoryObjectType.valueOf(ERepositoryObjectType.class, "ROUTE_DOC")) instanceof RouteDocumentItem);
}
Aggregations