use of org.apache.commons.lang3.StringUtils.isBlank in project kylo by Teradata.
the class DefaultFeedManagerFeedService method createFeed.
/**
* Create/Update a Feed in NiFi. Save the metadata to Kylo meta store.
*
* @param feedMetadata the feed metadata
* @return an object indicating if the feed creation was successful or not
*/
public NifiFeed createFeed(final FeedMetadata feedMetadata) {
// functional access to be able to create a feed
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_FEEDS);
feedHistoryDataReindexingService.checkAndConfigureNiFi(feedMetadata);
feedHistoryDataReindexingService.checkAndEnsureFeedHistoryDataReindexingRequestIsAcceptable(feedMetadata);
if (feedMetadata.getState() == null) {
if (feedMetadata.isActive()) {
feedMetadata.setState(Feed.State.ENABLED.name());
} else {
feedMetadata.setState(Feed.State.DISABLED.name());
}
}
if (StringUtils.isBlank(feedMetadata.getId())) {
feedMetadata.setIsNew(true);
}
// Read all the feeds as System Service account to ensure the feed name is unique
if (feedMetadata.isNew()) {
metadataAccess.read(() -> {
Feed existing = feedProvider.findBySystemName(feedMetadata.getCategory().getSystemName(), feedMetadata.getSystemFeedName());
if (existing != null) {
throw new DuplicateFeedNameException(feedMetadata.getCategoryName(), feedMetadata.getFeedName());
}
}, MetadataAccess.SERVICE);
}
NifiFeed feed = createAndSaveFeed(feedMetadata);
// register the audit for the update event
if (feed.isSuccess() && !feedMetadata.isNew()) {
Feed.State state = Feed.State.valueOf(feedMetadata.getState());
Feed.ID id = feedProvider.resolveId(feedMetadata.getId());
notifyFeedStateChange(feedMetadata, id, state, MetadataChange.ChangeType.UPDATE);
} else if (feed.isSuccess() && feedMetadata.isNew()) {
// update the access control
feedMetadata.toRoleMembershipChangeList().stream().forEach(roleMembershipChange -> securityService.changeFeedRoleMemberships(feed.getFeedMetadata().getId(), roleMembershipChange));
}
feedHistoryDataReindexingService.updateHistoryDataReindexingFeedsAvailableCache(feedMetadata);
return feed;
}
use of org.apache.commons.lang3.StringUtils.isBlank in project kylo by Teradata.
the class DatasourceController method getAllowedPermissionsChange.
@GET
@Path("{id}/actions/change")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Constructs and returns a permission change request for a set of users/groups containing the actions that the requester may permit or revoke.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the change request that may be modified by the client and re-posted.", response = PermissionsChange.class), @ApiResponse(code = 400, message = "The type is not valid.", response = RestResponseStatus.class), @ApiResponse(code = 404, message = "No data source exists with the specified ID.", response = RestResponseStatus.class) })
public Response getAllowedPermissionsChange(@PathParam("id") final String datasourceIdStr, @QueryParam("type") final String changeType, @QueryParam("user") final Set<String> userNames, @QueryParam("group") final Set<String> groupNames) {
if (StringUtils.isBlank(changeType)) {
throw new WebApplicationException("The query parameter \"type\" is required", Response.Status.BAD_REQUEST);
}
Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames)).collect(Collectors.toSet());
Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames)).collect(Collectors.toSet());
return this.securityService.createDatasourcePermissionChange(datasourceIdStr, PermissionsChange.ChangeType.valueOf(changeType.toUpperCase()), Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet())).map(p -> Response.ok(p).build()).orElseThrow(() -> new WebApplicationException("A data source with the given ID does not exist: " + datasourceIdStr, Response.Status.NOT_FOUND));
}
use of org.apache.commons.lang3.StringUtils.isBlank in project kylo by Teradata.
the class ImportUtil method applyImportPropertiesToTemplate.
public static boolean applyImportPropertiesToTemplate(RegisteredTemplate template, ImportTemplate importTemplate, ImportComponent component) {
ImportComponentOption option = importTemplate.getImportOptions().findImportComponentOption(component);
if (!option.getProperties().isEmpty() && option.getProperties().stream().anyMatch(importProperty -> StringUtils.isBlank(importProperty.getPropertyValue()))) {
importTemplate.setSuccess(false);
importTemplate.setTemplateResults(new NifiProcessGroup());
String msg = "Unable to import Template. Additional properties to be supplied before importing.";
importTemplate.getTemplateResults().addError(NifiError.SEVERITY.WARN, msg, "");
option.getErrorMessages().add(msg);
return false;
} else {
template.getSensitiveProperties().forEach(nifiProperty -> {
ImportProperty userSuppliedValue = option.getProperties().stream().filter(importFeedProperty -> nifiProperty.getProcessorId().equalsIgnoreCase(importFeedProperty.getProcessorId()) && nifiProperty.getKey().equalsIgnoreCase(importFeedProperty.getPropertyKey())).findFirst().orElse(null);
// deal with nulls?
if (userSuppliedValue == null) {
// attempt to find it via the name
userSuppliedValue = option.getProperties().stream().filter(importFeedProperty -> nifiProperty.getProcessorName().equalsIgnoreCase(importFeedProperty.getProcessorName()) && nifiProperty.getKey().equalsIgnoreCase(importFeedProperty.getPropertyKey())).findFirst().orElse(null);
}
if (userSuppliedValue != null) {
nifiProperty.setValue(userSuppliedValue.getPropertyValue());
}
});
return true;
}
}
use of org.apache.commons.lang3.StringUtils.isBlank in project ORCID-Source by ORCID.
the class SalesForceManagerImpl method createOpportunityContact.
private void createOpportunityContact(Contact contact, String opportunityId) {
String accountId = contact.getAccountId();
String contactOrcid = contact.getOrcid();
if (StringUtils.isBlank(contact.getEmail())) {
Email primaryEmail = emailManager.getEmails(contactOrcid).getEmails().stream().filter(e -> e.isPrimary()).findFirst().get();
contact.setEmail(primaryEmail.getEmail());
}
List<Contact> existingContacts = salesForceDao.retrieveAllContactsByAccountId(accountId);
Optional<Contact> existingContact = existingContacts.stream().filter(c -> {
if ((contact.getOrcid() != null && contact.getOrcid().equals(c.getOrcid())) || (contact.getEmail() != null && contact.getEmail().equals(c.getEmail()))) {
return true;
}
return false;
}).findFirst();
String contactId = existingContact.isPresent() ? existingContact.get().getId() : salesForceDao.createContact(contact);
OpportunityContactRole contactRole = new OpportunityContactRole();
contactRole.setContactId(contactId);
contactRole.setRoleType(ContactRoleType.MAIN_CONTACT);
contactRole.setOpportunityId(opportunityId);
salesForceDao.createOpportunityContactRole(contactRole);
addSalesForceConnection(accountId, contact);
}
use of org.apache.commons.lang3.StringUtils.isBlank in project eol-globi-data by jhpoelen.
the class CitationUtil method citationFor.
public static String citationFor(Dataset dataset) {
String defaultCitation = "<" + dataset.getArchiveURI().toString() + ">";
String citation = citationOrDefaultFor(dataset, defaultCitation);
if (!StringUtils.contains(citation, "doi.org") && !StringUtils.contains(citation, "doi:")) {
String citationTrimmed = StringUtils.trim(defaultString(citation));
String doiTrimmed = defaultString(dataset.getDOI());
if (StringUtils.isBlank(doiTrimmed)) {
citation = citationTrimmed;
} else {
citation = citationTrimmed + separatorFor(citationTrimmed) + doiTrimmed;
}
}
return StringUtils.trim(citation);
}
Aggregations