本文整理汇总了Java中org.talend.daikon.exception.ExceptionContext类的典型用法代码示例。如果您正苦于以下问题:Java ExceptionContext类的具体用法?Java ExceptionContext怎么用?Java ExceptionContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExceptionContext类属于org.talend.daikon.exception包,在下文中一共展示了ExceptionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPossibleValuesDisplayName
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
/**
* This will look if {@link NamedThing} where used as possible values and use associated
* {@link NamedThing#getDisplayName()}. If there are possible Values as NamedThing and the value is not found the an
* exception is thrown. If no NamedThing was set as possible values it will delegate to
* {@link Property#getPossibleValuesDisplayName(Object)}
*
* @return the associated {@link NamedThing#getDisplayName()} if found or the default i18n value from super.
* @throws TalendRuntimeException is the possible value does not belong to the list of possible values.
*/
@Override
public String getPossibleValuesDisplayName(Object possibleValue) {
String possibleValueDisplayName = possibleValue == null ? "null" : possibleValue.toString();
// first check that the possibleValue is part of the possible values
if (!isAPossibleValue(possibleValue)) {
throw new TalendRuntimeException(CommonErrorCodes.UNEXPECTED_ARGUMENT,
ExceptionContext.build().put("argument", "possibleValues").put("value", possibleValue));
}
// look for the named thing named possibleValue and return it's display name if not null
if (possibleValues2 != null && !possibleValues2.isEmpty()) {
for (NamedThing nt : possibleValues2) {
if (possibleValue != null && possibleValue.equals(nt.getName())) {
possibleValueDisplayName = (nt.getDisplayName() != null ? nt.getDisplayName() : nt.getName());
break;
} // else keep looking
}
} else {// delegate to super.
possibleValueDisplayName = super.getPossibleValuesDisplayName(possibleValue);
}
return possibleValueDisplayName;
}
示例2: getPossibleValuesDisplayName
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
/**
* Return a i18n String for a given possible value. It will automatically look for the key
* {@value Property#I18N_PROPERTY_PREFIX}.possibleValue.getDisplayName(). {@value NamedThing#I18N_DISPLAY_NAME_SUFFIX}. if the
* key
* is not found it returns the possibleValue.toString().
*
* @return a I18n value or possibleValue.toString if the value is not found.
* @exception TalendRuntimeException with {@link CommonErrorCodes#UNEXPECTED_ARGUMENT} if the possible value does not belong
* to possible values
*/
public String getPossibleValuesDisplayName(Object possibleValue) {
// first check that the possibleValue is part of the possible values
if (!isAPossibleValue(possibleValue)) {
throw new TalendRuntimeException(CommonErrorCodes.UNEXPECTED_ARGUMENT,
ExceptionContext.build().put("argument", "possibleValues").put("value", possibleValue));
}
if (possibleValue != null) {
String possibleValueDisplayName = possibleValue.toString();
if (NamedThing.class.isAssignableFrom(possibleValue.getClass())) {
possibleValueDisplayName = ((NamedThing) possibleValue).getDisplayName();
}
String i18nMessage = getI18nMessage(
I18N_PROPERTY_POSSIBLE_VALUE_PREFIX + possibleValueDisplayName + NamedThing.I18N_DISPLAY_NAME_SUFFIX);
if (i18nMessage.endsWith(NamedThing.I18N_DISPLAY_NAME_SUFFIX)) {
return possibleValueDisplayName;
} else {
return i18nMessage;
}
} else {
return "null";
}
}
示例3: testDeserialize
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
@Test
public void testDeserialize() throws IOException {
// check that the CodeError serialization can be deserialized into an JsonCodeError
TalendRuntimeException talendRuntimeException = new TalendRuntimeException(CommonErrorCodes.MISSING_I18N_TRANSLATOR,
ExceptionContext.build().put("key", "the key").put("baseName", "the baseName"));
StringWriter writer = new StringWriter();
talendRuntimeException.writeTo(writer);
ObjectMapper objectMapper = new ObjectMapper();
JsonErrorCode deserializedCode = objectMapper.reader(JsonErrorCode.class).readValue(writer.toString());
ErrorCode expectedCode = talendRuntimeException.getCode();
assertEquals(expectedCode.getCode(), deserializedCode.getCode());
assertEquals(expectedCode.getGroup(), deserializedCode.getGroup());
assertEquals(expectedCode.getProduct(), deserializedCode.getProduct());
assertThat(expectedCode.getExpectedContextEntries(),
containsInAnyOrder(deserializedCode.getExpectedContextEntries().toArray()));
assertThat(talendRuntimeException.getContext().entries(),
containsInAnyOrder(deserializedCode.getContext().entrySet().toArray()));
}
示例4: getWizardPngImage
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
@Override
public InputStream getWizardPngImage(String wizardName, WizardImageType imageType) {
Map<String, ComponentWizardDefinition> wizardsDefs = definitionRegistry
.getDefinitionsMapByType(ComponentWizardDefinition.class);
if (wizardsDefs.isEmpty()) {
throw TalendRuntimeException.createUnexpectedException("fails to retrieve any Wizard defintions.");
}
ComponentWizardDefinition wizardDefinition = wizardsDefs.get(wizardName);
if (wizardDefinition != null) {
return getImageStream(wizardDefinition, wizardDefinition.getPngImagePath(imageType));
} else {
throw new ComponentException(ComponentsApiErrorCode.WRONG_WIZARD_NAME,
ExceptionContext.build().put("name", wizardName)); //$NON-NLS-1$
}
}
示例5: getSchema
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
/**
* This default implementation uses {@link PropertyPathConnector} to find the SchemaProperties or Property of type
* Schema instances avaialble in this Object. It return null if none found
*/
@SuppressWarnings("unchecked")
@Override
public Schema getSchema(Connector connector, boolean isOutputConnection) {
if (connector instanceof PropertyPathConnector) {
NamedThing property = getProperty(((PropertyPathConnector) connector).getPropertyPath());
if (property != null) {
Property<Schema> schemaProp = null;
if (property instanceof SchemaProperties) {
SchemaProperties schemaProperties = (SchemaProperties) property;
schemaProp = schemaProperties.schema;
} else if (property instanceof Property) {
schemaProp = (Property<Schema>) property;
}
return schemaProp != null ? schemaProp.getValue() : null;
} else {// else path not found so throw exception
throw new ComponentException(ComponentsErrorCode.WRONG_CONNECTOR,
ExceptionContext.build().put("properties", this.getClass().getCanonicalName()));
}
} // else not a connector handled by this class so return null
return null;
}
示例6: setConnectedSchema
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void setConnectedSchema(Connector connector, Schema schema, boolean isOutputConnection) {
if (connector instanceof PropertyPathConnector) {
NamedThing property = getProperty(((PropertyPathConnector) connector).getPropertyPath());
if (property != null) {
if (property instanceof SchemaProperties) {
SchemaProperties schemaProperties = (SchemaProperties) property;
schemaProperties.schema.setValue(schema);
} else if (property instanceof Property) {
((Property<Schema>) property).setValue(schema);
}
} else {// else path not found so throw exception
throw new ComponentException(ComponentsErrorCode.WRONG_CONNECTOR,
ExceptionContext.build().put("properties", this.getClass().getCanonicalName()));
}
} // not a connector handled by this class
}
示例7: getMavenUrlDependencies
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
@Override
public List<URL> getMavenUrlDependencies() {
DependenciesReader dependenciesReader = new DependenciesReader(depTxtPath);
try {
Set<String> dependencies = dependenciesReader.getDependencies(classloader);
// convert the string to URL
List<URL> result = new ArrayList<>(dependencies.size());
for (String urlString : dependencies) {
result.add(new URL(urlString));
}
return result;
} catch (IOException e) {
throw new ComponentException(ComponentsApiErrorCode.COMPUTE_DEPENDENCIES_FAILED, e,
ExceptionContext.withBuilder().put("path", dependenciesReader.getDependencyFilePath()).build());
}
}
示例8: testJsonConverterError
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
@Test
public void testJsonConverterError() throws Exception {
NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
FieldDesc fieldDesc = typeDesc.getField("department");
AvroConverter<RecordRef, String> converter1 =
(AvroConverter<RecordRef, String>) transducer.getValueConverter(fieldDesc);
try {
converter1.convertToDatum("{name:'R&D',internalId:'12345',externalId:null,type:null}");
fail("NetSuiteException expected");
} catch (Exception e) {
assertThat(e, instanceOf(NetSuiteException.class));
NetSuiteException nsException = (NetSuiteException) e;
assertNotNull(nsException.getCode());
assertNotNull(nsException.getContext());
assertNotNull(nsException.getContext().get(ExceptionContext.KEY_MESSAGE));
}
}
示例9: buildSubquery
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
/**
* This method is used to build SOQL sub query for Parent to Child relation.<br/>
* Each child field name must conform pattern <code>{module_name}_records_{column_name}</code>.<br/>
* Where:
* <ul>
* <li><code>module_name</code> must be the same for each child field</li>
* <li><code>column_name</code> may be simple, custom or relational field</li>
* </ul>
* Example:<br/>
* <ol>
* <li>custom_module__r_records_Name</li>
* <li>custom_module__r_records_custom_name__c</li>
* <li>custom_module__r_records_Account_Name</li>
* </ol>
*
* <b> Result </b>
* <code>(SELECT Name, custom_name__c, Account.Name FROM custom_module__r)</code>
*
* @param inputStrings {@link java.util.List} is the list of child fields.
* @return {@link java.lang.StringBuilder} SOQL sub query.
*/
private StringBuilder buildSubquery(List<String> inputStrings) {
StringBuilder sb = new StringBuilder();
sb.append(LEFT_PARENTHESIS).append(SELECT_STATEMENT).append(SPACE_SEPARATOR);
String moduleName = null;
for (String item : inputStrings) {
String[] array = item.split(RECORDS);
String columnName = null;
//We expect only 2 values from splitting field tableName and columnName
if ((array.length != 2) || StringUtils.isBlank(array[0]) || StringUtils.isBlank(columnName = array[1])) {
// Should notify user about invalid table name or column name.
TalendRuntimeException.build(SalesforceErrorCodes.INVALID_SOQL)
.put(ExceptionContext.KEY_MESSAGE, "Relation Parent to Child has invalid child table name or column name")
.throwIt();
}
if (null == moduleName) {
moduleName = getSplittedValue(array[0]);
}
sb.append(getSplittedValue(columnName)).append(COMMA_AND_SPACE);
}
sb.delete(sb.length() - 2, sb.length());
sb.append(FROM_CLAUSE).append(moduleName).append(RIGHT_PARENTHESIS);
return sb;
}
示例10: delete
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
private DeleteResult[] delete(IndexedRecord input) throws IOException {
// Calculate the field position of the Id the first time that it is used. The Id field must be present in the
// schema to delete rows.
if (deleteFieldId == -1) {
String ID = "Id";
Schema.Field idField = input.getSchema().getField(ID);
if (null == idField) {
throw new ComponentException(new DefaultErrorCode(HttpServletResponse.SC_BAD_REQUEST, "message"),
ExceptionContext.build().put("message", ID + " not found"));
}
deleteFieldId = idField.pos();
}
String id = (String) input.get(deleteFieldId);
if (id != null) {
deleteItems.add(input);
if (deleteItems.size() >= commitLevel) {
return doDelete();
}
}
return null;
}
示例11: get
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
/**
* @see UserDataRepository#get(String)
*/
@Override
public UserData get(String userId) {
final File inputFile = getFile(userId);
if (inputFile.getName().startsWith(".")) {
LOG.info("Ignore hidden file {}", inputFile.getName());
return null;
}
if (!inputFile.exists()) {
LOG.debug("user data #{} not found in file system", userId);
return null;
}
try (GZIPInputStream input = new GZIPInputStream(new FileInputStream(inputFile))) {
return mapper.readerFor(UserData.class).readValue(input);
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNABLE_TO_READ_USER_DATA, e, ExceptionContext.build().put("id", userId));
}
}
示例12: checkParameters
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
/**
* Check that the selected column parameter is correct in case we concatenate with another column: defined in the
* parameters and there's a matching column. If the parameter is invalid, an exception is thrown.
*
* @param parameters where to look the parameter value.
* @param rowMetadata the row where to look for the column.
*/
private void checkParameters(Map<String, String> parameters, RowMetadata rowMetadata) {
if (!parameters.containsKey(MODE_PARAMETER)) {
throw new TalendRuntimeException(ActionErrorCodes.BAD_ACTION_PARAMETER,
ExceptionContext.build().put("paramName", MODE_PARAMETER));
}
if (parameters.get(MODE_PARAMETER).equals(CONSTANT_MODE) && !parameters.containsKey(DEFAULT_VALUE_PARAMETER)) {
throw new TalendRuntimeException(ActionErrorCodes.BAD_ACTION_PARAMETER,
ExceptionContext.build().put("paramName", DEFAULT_VALUE_PARAMETER));
}
if (parameters.get(MODE_PARAMETER).equals(COLUMN_MODE) && (!parameters.containsKey(SELECTED_COLUMN_PARAMETER)
|| rowMetadata.getById(parameters.get(SELECTED_COLUMN_PARAMETER)) == null)) {
throw new TalendRuntimeException(ActionErrorCodes.BAD_ACTION_PARAMETER,
ExceptionContext.build().put("paramName", SELECTED_COLUMN_PARAMETER));
}
}
示例13: checkSelectedColumnParameter
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
/**
* Check that the selected column parameter is correct in case we check contains with another column: defined in the
* parameters and there's a matching column. If the parameter is invalid, an exception is thrown.
*
* @param parameters where to look the parameter value.
* @param rowMetadata the row metadata where to look for the column.
*/
private void checkSelectedColumnParameter(Map<String, String> parameters, RowMetadata rowMetadata) {
if (!parameters.containsKey(MODE_PARAMETER)) {
throw new TalendRuntimeException(ActionErrorCodes.BAD_ACTION_PARAMETER, ExceptionContext.build().put("paramName",
MODE_PARAMETER));
}
if (parameters.get(MODE_PARAMETER).equals(OTHER_COLUMN_MODE)
&& (!parameters.containsKey(SELECTED_COLUMN_PARAMETER) || rowMetadata.getById(parameters
.get(SELECTED_COLUMN_PARAMETER)) == null)) {
throw new TalendRuntimeException(ActionErrorCodes.BAD_ACTION_PARAMETER, ExceptionContext.build().put("paramName",
SELECTED_COLUMN_PARAMETER));
}
if (parameters.get(MODE_PARAMETER).equals(CONSTANT_MODE) && (!parameters.containsKey(CONSTANT_VALUE))) {
throw new TalendRuntimeException(ActionErrorCodes.BAD_ACTION_PARAMETER, ExceptionContext.build().put("paramName",
CONSTANT_VALUE));
}
}
示例14: checkParameters
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
/**
* Check that the selected column parameter is correct : defined in the parameters and there's a matching column. If
* the parameter is invalid, an exception is thrown.
*
* @param parameters where to look the parameter value.
* @param rowMetadata the row metadata where to look for the column.
*/
private void checkParameters(Map<String, String> parameters, RowMetadata rowMetadata) {
if (!parameters.containsKey(MODE_PARAMETER)) {
throw new TalendRuntimeException(ActionErrorCodes.BAD_ACTION_PARAMETER,
ExceptionContext.build().put("paramName", MODE_PARAMETER));
}
if (parameters.get(MODE_PARAMETER).equals(CONSTANT_MODE) && !parameters.containsKey(DEFAULT_VALUE_PARAMETER)) {
throw new TalendRuntimeException(ActionErrorCodes.BAD_ACTION_PARAMETER,
ExceptionContext.build().put("paramName", DEFAULT_VALUE_PARAMETER));
} else if (!parameters.get(MODE_PARAMETER).equals(CONSTANT_MODE) && (!parameters.containsKey(SELECTED_COLUMN_PARAMETER)
|| rowMetadata.getById(parameters.get(SELECTED_COLUMN_PARAMETER)) == null)) {
throw new TalendRuntimeException(ActionErrorCodes.BAD_ACTION_PARAMETER,
ExceptionContext.build().put("paramName", SELECTED_COLUMN_PARAMETER));
}
}
示例15: getActions
import org.talend.daikon.exception.ExceptionContext; //导入依赖的package包/类
/**
* Returns the actions for the preparation with <code>preparationId</code> at given <code>stepId</code>.
*
* @param preparationId The preparation id, if <code>null</code> or blank, returns <code>{actions: []}</code>
* @param stepId A step id that must exist in given preparation id.
* @return The actions that can be parsed by ActionParser.
* @see org.talend.dataprep.transformation.api.action.ActionParser
*/
protected String getActions(String preparationId, String stepId) {
String actions;
if (StringUtils.isBlank(preparationId)) {
actions = "{\"actions\": []}";
} else {
final PreparationGetActions getActionsCommand = applicationContext.getBean(PreparationGetActions.class, preparationId,
stepId);
try {
actions = "{\"actions\": " + IOUtils.toString(getActionsCommand.execute(), UTF_8) + '}';
} catch (IOException e) {
final ExceptionContext context = ExceptionContext.build().put("id", preparationId).put("version", stepId);
throw new TDPException(UNABLE_TO_READ_PREPARATION, e, context);
}
}
return actions;
}