How to use an if statement with match expresion in Groovy - groovy

I have the following groovy code where /data/JarFiles/ contain many .jar files and /data/XML/Platform/ contain some xml files used to launch the jar:
Jar=[]
path = "/data/JarFiles"
new File(path).eachFileMatch(~/.*.jar/) {
Jar.add(it)
}
return Jar.sort{it.lastModified()}.collect{it.name}.reverse()
if (Jar.equals("Core2_v4.1.6.jar") && Product.equals("maximus")) {
Platform=[]
path2 = "/data/XML/Platform/"
new File(path2).eachFileMatch(~/.*K6_Platform.*/) {
Platform.add(it.getName())
}
return Platform.sort()
I want to do something like this:
...
if (Jar.Match(~/.*Core2_v4.*/) && Product.equals("maximus")) {
...
Can somebody help me with this please?
Thank you!

here is the sample that works fine
def Jar = ['sdfgsdfg', 'Core2_v4.1.jar', 'aaa', 'bbb']
def Product = "maximus"
if( Jar.find{it=~/Core2_v4/} && Product=="maximus" ){
println "OK"
}else{
println "Failed"
}

The solution that works perfectly for me is:
Jar=[]
path = "/data/JarFiles"
new File(path).eachFileMatch(~/.*.jar/) {
Jar.add(it)
}
return Jar.sort{it.lastModified()}.collect{it.name}.reverse()
if (Jar=~/Core2_v4/) && Product.equals("maximus")) {
Platform=[]
path2 = "/data/XML/Platform/"
new File(path2).eachFileMatch(~/.*K6_Platform.*/) {
Platform.add(it.getName())
}
return Platform.sort()

Related

How to use export excel file with excel 1.1.5 package

I'm currently using this package Excel 1.1.5 ... It currently has a method called save but it just returns a List integers...and I don't know where to go from here..
List<int>? potato = excel.save(fileName: 'namePotato');
Hoping you guys can help!
Thanks!
Found the answer, you can use dart:io and I've also used Permissions_handler
Future exportReport() async {
var excel = Excel.createExcel();
DateTime _now = DateTime.now();
String _name = DateFormat('yyyy-MM-dd').format(_now);
String _fileName = 'surname-' + _name;
List<int>? potato = excel.save(fileName: _name);
PermissionStatus status = await Permission.storage.request();
if (status == PermissionStatus.granted) {
await File('/storage/emulated/0/Download/$_fileName.xlsx').writeAsBytes(potato!, flush: true).then((value) {
log('saved');
});
} else if (status == PermissionStatus.denied) {
log('Denied. Show a dialog with a reason and again ask for the permission.');
} else if (status == PermissionStatus.permanentlyDenied) {
log('Take the user to the settings page.');
}
return null;
}

Unable to access an error message corresponding to your field name -while uploading file in fuel cms in MY_Form_validation

I have written an validation rule on MY_Form_validation class under application -> library folder
as follow ..
public function doc_uploaded($field,$types)
{
$types=explode(',',$types);
$upload = $this->CI->lang->line('upload');
if(isset($_FILES[$field]) && !empty($_FILES[$field]['name']))
{
if(!function_exists('file_upload')){ $this->CI->load->helper('MY_file_helper'); }
$status = file_upload(($field),$_FILES[$field], captcha_path(),$types);
if($status >0 or strlen($status) > 2 )
{
return TRUE;
}
elseif(is_array($status))
{
$this->CI->_error_array[$field] = $status[0];
$this->CI->_error_array[$field] = $status[0];
$this->_error_array[$field]=sprintf( $upload,$this->_translate_fieldname($this->_field_data[$field]['label']));
// echo $field, print_r($this->_error_array);
// print_r($this->CI->_error_array);die();
return FALSE;
}
else
{
$this->_error_array[$field] = $status[0];
return FALSE;
}
}
else
{
return FALSE;
}
}
i am setting the validation rule from controller as follow
$this->form_validation->set_rules('resume', 'Resume', 'required|doc_uploaded[pdf,doc,docx,odt,txt,ppt,pptx]');
$_POST['resume'] ='resume';
now this one working fine except that error massage :
Unable to access an error message corresponding to your field name
Resume.(doc_uploaded)
must be an way to fix it please help . iam using 1.4
instead of
$this->_error_array[$field] = $status[0];
using
$this->CI->form_validation->set_message('doc_uploaded',$status[0]);
resolved the issue

Groovy syntax error

I have an error ("unexpected token"). I don't know Groovy very well , but how to fix it? Part of my code:
def PriorityQueue<Agent> agentPQ = new PriorityQueue<>(agents.size(), new Comparator<Agent>() {
#Override
int compare(Agent o1, Agent o2) {
if(o1.issueCount == o2.issueCount){
if(o2.lastAssignedTime == o1.lastAssignedTime){
return o1.user.name.compareTo(o2.user.name)
}
else{
return o1.lastAssignedTime.compareTo(o2.lastAssignedTime)
}
}
else{
return o1.issueCount - o2.issueCount
}
}
})
I have an error in &lt case
Your problem is caused by HTML entities that encoded < and > characters:
def PriorityQueue<Agent> agentPQ = new PriorityQueue<>(agents.size(), new Comparator<Agent>() {
It should be:
def PriorityQueue<Agent> agentPQ = new PriorityQueue<>(agents.size(), new Comparator<Agent>() {
The code you have pasted wont compile neither in Groovy nor in Java.

Pagination link not work properly?

Pagination not work properly?
I saved this code in "Forum-Com.php" file and when i open this file, pagination works properly and correctly but when I include this file in another page, its open first page correctly but when I click second or another page link it open same comments which are on first page. Please help me. ( I am using Scriptsmill comments script v1.06 and function make_pages_string from admin.php )
$COM_CONF['full_path'] = dirname(__FILE__);
function make_pages_string ($all_count, $records_per_page, $cur_page, $base_url) {
if ($all_count > $records_per_page) {
if ($cur_page > 0) { $cur_page=$cur_page-1; }
$first_record = ($cur_page) * $records_per_page;
$limit_string = "LIMIT $first_record, $records_per_page";
$pages=$all_count/$records_per_page;
if ($pages > (int) $pages) { $pages=(int)$pages+1; }
}
if ($pages>1) {
$pages_string.="Page: ";
if ($cur_page>10 && $pages>20) { $first_page=$cur_page-9; }
else { $first_page=1; }
if ($pages>20 && ($cur_page+10)<$pages) { $last_page=$first_page+19; }
else { $last_page=$pages; }
if ($cur_page+1>1) {
$prev=$cur_page;
$pages_string.="<a href='$base_url&page=$prev'>&lt</a> ";
}
for ($i=$first_page; $i<=$last_page; $i++){
if ($i != $cur_page+1) {
$pages_string.="<a href='$base_url&page=$i'>$i</a> ";
}
else {
$pages_string.="<b>$i</b> ";
}
}
if ($cur_page+1<$pages) {
$next=$cur_page+2;
$pages_string.="<a href='$base_url&page=$next'>&gt</a> ";
}
}
return array ($pages_string, $limit_string);
}
function smcom_view()
{
global $comments_db_link, $COM_CONF, $COM_LANG;
$result = mysql_query("select COUNT(id) from {$COM_CONF['dbmaintable']}", $comments_db_link);
list ($all_count) = mysql_fetch_row($result);
list ($pages_string, $limit_string) = make_pages_string ($all_count, 10, $_REQUEST['page'], "{$COM_CONF['base_url']}?action=view");
$result = mysql_query("select time, text, author, email, dont_show_email from {$COM_CONF['dbmaintable']} order by time {$COM_CONF['sort_order']} $limit_string", $comments_db_link);
$comments_count=0;
$id=$time=$text=$author=$email=$dont_show_email=$ip=array();
while (list($id[$comments_count], $time[$comments_count], $text[$comments_count], $author[$comments_count], $email[$comments_count], $dont_show_email[$comments_count], $ip[$comments_count])=mysql_fetch_array($result)) {
$comments_count++;
}
require("{$COM_CONF['full_path']}/templates/Forum-default.php");
}
The code given above has no problem at all. The problem is with the server configuration which turned off $_REQUEST global variable from direct access.

Scan directories in groovy with ant builder file scanner

I want to use fileScanner of AntBuilder to go over directories.
My code looks like:
scanner = new AntBuilder().fileScanner {
fileset(dir:sourcedir, casesensitive:false) {
include(name:pattern)
type(type:'dir')
}
}
I want to loop with the scanner just on directories, for example:
for (file in scanner) {
assert file.directory == true
}
Any idea ?
Thanks!!!!!!!!
Here's how to do it with fileScanner
scanner = new AntBuilder().fileScanner {
fileset(dir:sourcedir, casesensitive:false) {
include(name:pattern)
}
}
// Just the directories
scanner.directories().each {
println it.name
}
You could also do it with Groovy calls:
def dirs = []
new File( sourcedir ).eachDirRecurse {
// Check the name here, obviously the Ant pattern you have probably won't work
if( it.name ==~ pattern ) dirs << it
}
dirs.each {
println it.name
}

Resources