How to pass an object dynamically in the define function of Ext object in Sencha ExtJS 6.0.2? - class

Taking a look at the following segment of code you will see two cases where the sencha cmd return an error and one case that it doesn't
var memoryStore = new MemoryStore<Individual>("personnel", [
'name', 'email', 'phone'
], [
new Individual("Batman", "etsigoustaro#thefirm.com", "+306969696969"),
new Individual("Jean Luc", "jeanluc.picard#enterprise.com", "555-111-1111"),
new Individual("Worf", "worf.moghsson#enterprise.com", "+30 696 969 6969"),
new Individual("Deanna", "mr.data#enterprise.com", "+30 6969696969"),
new Individual("Data", "deanna.troi#enterprise.com", "+30-6969696969"),
])
//memoryStore.toExtJS()
Ext.define('extTestTs.store.Personnel', (function(){
//return JSON.stringify(memoryStore.toExtJS()) //fails
//return Ext.Object.merge({},{}) //fails
return {} //succeeds
})());
As you see we have removed everything, even extends is missing but as long as you are typing an object by hand it works. When this object is returned from a function it stops to work!
What does the sencha cmd does behind the scenes? Is it parsing the plain javascript as a text file?..
Because if it was javascript it would run without an issue.
This is the error from sencha cmd console output:
[ERR] C2008: Requirement had no matching files (extTestTs.store.Personnel) -- /home/student/Desktop/Typescript/extTestTs/classic/src/view/main/List.js:8:10
[ERR]
[ERR] BUILD FAILED
[ERR] com.sencha.exceptions.ExBuild: Failed to find any files for /home/student/Desktop/Typescript/extTestTs/classic/src/view/main/List.js::ClassRequire::extTestTs.store.Personnel
[ERR]
[ERR] Total time: 3 seconds
[ERR] The following error occurred while executing this line:
/home/student/bin/Sencha/Cmd/6.1.2.15/plugins/ext/current/plugin.xml:425: The following error occurred while executing this line:
/home/student/Desktop/Typescript/extTestTs/.sencha/app/build-impl.xml:380: The following error occurred while executing this line:
/home/student/Desktop/Typescript/extTestTs/.sencha/app/init-impl.xml:382: com.sencha.exceptions.ExBuild: Failed to find any files for /home/student/Desktop/Typescript/extTestTs/classic/src/view/main/List.js::ClassRequire::extTestTs.store.Personnel
How could we overcome this restriction of explicitly defining the object and rather define it more dynamically?
The goal is to make typescript work with ExtJS but not with the extreme unconventional solutions others propose, like forking typescript itself

Found a workaround
First allow unreachable code in typescript
Here is a screenshot from the IntelliJ settings:
And the code in the questions transforms into that
var memoryStore = new MemoryStore<Individual>("personnel", [
'name', 'email', 'phone'
], [
new Individual("Batman", "etsigoustaro#thefirm.com", "+306969696969"),
new Individual("Jean Luc", "jeanluc.picard#enterprise.com", "555-111-1111"),
new Individual("Worf", "worf.moghsson#enterprise.com", "+30 696 969 6969"),
new Individual("Deanna", "mr.data#enterprise.com", "+30 6969696969"),
new Individual("Data", "deanna.troi#enterprise.com", "+30-6969696969"),
])
//memoryStore.toExtJS()
Ext.define('extTestTs.store.Personnel', function (Personnel) {
return memoryStore.toExtJS()
return {} //do not erase this line
});
Yeah the line return {} might seem totally redundant but (obviously) the sencha cmd is trying to parse the file before it includes it in the requires
Now sencha cmd gives a success and executing sencha app web start the sample app works ok

Related

All Dingo routes return 404 when phpunit testing

original posted at https://github.com/dingo/api/issues/1472
I'm using Lumen 5.1 and DingoApi 1.0.x to do my api development, and now I'm trying to do some acceptance testing. Following the documentation of Lumen, here is how I do it:
Here is a simplified routes definition in app\Http\routes.php:
$app->get('/', function () use ($app) {
return "Welcome to mysite.com";
});
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
$api->group([
'prefix' => 'dealer',
'middleware' => 'checkH5ApiSign'
], function ($api) {
$api->get('list', 'App\Http\Controllers\Credit\DealerController#index');
$api->get('staff_list', 'App\Http\Controllers\Credit\DealerController#getStaffList');
});
}
I can access both routes defined using $app or $api(dingo) in browser or via postman, they both can return a 200 response. But whenever I'm trying to access those routes in phpunit, the $app defined route like / is responding okay with 200 code, but all routes defined with $api(dingo) will response with 404 status code. Here is my test code:
class DealerTest extends TestCase
{
public function testTest()
{
$this->get('/')->assertResponseOk();
$this->get('/dealer/list')->assertResponseOk();
$this->get('/dealer/staff_list')->assertResponseOk();
}
}
and ran result:
PHPUnit 5.7.5 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 590 ms, Memory: 6.00MB
There was 1 failure:
1) DealerTest::testTest
Expected status code 200, got 404.
Failed asserting that false is true.
E:\Gitrepos\api.fin.youxinjinrong.com\vendor\laravel\lumen-framework\src\Testing\AssertionsTrait.php:19
E:\Gitrepos\api.fin.youxinjinrong.com\tests\DealerTest.php:8
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
I tried ran through Dingo package code to find the cause, but failed. All other related issue could not solve my problem either. So please help me.
update
I followed the code flow, and see that FastRoute\DataGenerator\RegexBasedAbstract.php is doing the addRoute() operation, I dumped $this->staticRoutes) in that addRoute() method, see that it's doing okay both inside browser and under phpunit. But weird enough, the following call of ->getData() is behaving differenctly: in browser all static routes are returned, but not in phpunit.
Hope this can somehow be helpful. I'm still digging this problem...
So I got mine to work by doing this;
Using the example in the example used in creating the issue:
class DealerTest extends TestCase
{
public function testTest()
{
$this->get('/')->assertResponseOk();
$this->get('/dealer/list')->assertResponseOk();
$this->get('/dealer/staff_list')->assertResponseOk();
}
}
becomes
class DealerTest extends TestCase
{
public function testTest()
{
$this->get(getenv('API_DOMAIN') . '/v1/')->assertResponseOk();
$this->get(getenv('API_DOMAIN') . '/v1/dealer/list')->assertResponseOk();
$this->get(getenv('API_DOMAIN') . '/v1/dealer/staff_list')->assertResponseOk();
}
}
I hope this helps

ReactiveMongo/Play: `LastError: DatabaseException['<none>']`, while db still updates

weird problem: While my play application tries to insert/update records from some mongoDB collections while using reactivemongo, the operation seems to fail with a mysterious message, but the record does, actually, gets inserted/updated.
More info:
Insert to problematic collections from the mongo console works well
reading from all collections works well
reading and writing to other collections in the same db works well
writing to the problematic collections used to work.
Error message is:
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[LastError: DatabaseException['<none>']]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70)
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40)
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248)
Caused by: reactivemongo.api.commands.LastError: DatabaseException['<none>']
Using ReactiveMongo 0.11.14, Play 2.5.4, Scala 2.11.7, MongoDB 3.4.0.
Thanks!
UPDATE - The mystery thickens!
Based on #Yaroslav_Derman's answer, I added a .recover clause, like so:
collectionRef.flatMap( c =>
c.update( BSONDocument("_id" -> publicationWithId.id.get), publicationWithId.asInstanceOf[PublicationItem], upsert=true))
.map(wr => {
Logger.warn("Write Result: " + wr )
Logger.warn("wr.inError: " + wr.inError)
Logger.warn("*************")
publicationWithId
}).recover({
case de:DatabaseException => {
Logger.warn("DatabaseException: " + de.getMessage())
Logger.warn("Cause: " + de.getCause())
Logger.warn("Code: " + de.code)
publicationWithId
}
})
The recover clause does get called. Here's the log:
[info] application - Saving pub t3
[warn] application - *************
[warn] application - Saving publication Publication(Some(BSONObjectID("5848101d7263468d01ff390d")),t3,2016-12-07,desc,auth,filename,None)
[info] application - Resolving database...
[info] application - Resolving database...
[warn] application - DatabaseException: DatabaseException['<none>']
[warn] application - Cause: null
[warn] application - Code: None
So no cause, no code, message is "'<none>'", but still an error. What gives?
I tried to move to 0.12, but that caused some compilation errors across the app, plus I'm not sure that would solve the problem. So I'd like to understand what's wrong first.
UPDATE #2:
Migrated to reactive-mongo 0.12.0. Problem persists.
Problem solved by downgrading to MongoDB 3.2.8. Turns out reactiveMongo 0.12.0 is not compatible with mongoDB 3.4.
Thanks everyone who looked into this.
For play reactivemongo 0.12.0 you can do like this
def appsDb = reactiveMongoApi.database.map(_.collection[JSONCollection](DesktopApp.COLLECTION_NAME))
def save(id: String, user: User, body: JsValue) = {
val version = (body \ "version").as[String]
val app = DesktopApp(id, version, user)
appsDb.flatMap(
_.insert(app)
.map(_ => app)
.recover(processError)
)
}
def processError[T]: PartialFunction[Throwable, T] = {
case ex: DatabaseException if ex.code.contains(10054 | 10056 | 10058 | 10107 | 13435 | 13436) =>
//Custom exception which processed in Error Handler
throw new AppException(ResponseCode.ALREADY_EXISTS, "Entity already exists")
case ex: DatabaseException if ex.code.contains(10057 | 15845 | 16550) =>
//Custom exception which processed in Error Handler
throw new AppException(ResponseCode.ENTITY_NOT_FOUND, "Entity not found")
case ex: Exception =>
//Custom exception which processed in Error Handler
throw new InternalServerErrorException(ex.getMessage)
}
Also you can add logs in processError method
LastError was deprecated in 0.11, replaced by WriteResult.
LastError does not, actually, means error, it could mean successful result, you need to check inError property of the LastError object to detect if it's real error. As I see, the '<none>' error message give a good chance that this is not error.
Here is the example "how it was in 0.10": http://reactivemongo.org/releases/0.10/documentation/tutorial/write-documents.html

Annotating a corpus using Syntaxnet

I am trying to annotate a corpus using Syntaxnet. I added the following lines in the end of the /models/syntaxnet/syntaxnet/models/parsey_mcparseface/context.pbtxt file:
input {
name: 'input_file'
record_format: 'english-text'
Part {
file_pattern: '/home/melvyn/text.txt'
}
}
output {
name: 'output_file'
record_format: 'english-text'
Part {
file_pattern: '/home/melvyn/text-tagged.txt'
}
}
When i run the command:
./demo.sh --input=input_file --output=output_file
I am getting:
./demo.sh: line 31: bazel-bin/syntaxnet/parser_eval: No such file or directory
./demo.sh: line 43: bazel-bin/syntaxnet/parser_eval: No such file or directory
./demo.sh: line 55: bazel-bin/syntaxnet/conll2tree: No such file or directory
According to the answer given ## here ## I changed my demo.sh file and now I get some errors which say:
[libprotobuf ERROR external/tf/google/protobuf/src/google/protobuf/text_format.cc:291] Error parsing text-format syntaxnet.TaskSpec: 200:8: Message type "syntaxnet.TaskOutput" has no field named "Part".
E external/tf/tensorflow/core/framework/op_segment.cc:53] Create kernel failed: Invalid argument: Could not parse task context at syntaxnet/models/parsey_mcparseface/context.pbtxt
E external/tf/tensorflow/core/common_runtime/executor.cc:333] Executor failed to create kernel. Invalid argument: Could not parse task context at syntaxnet/models/parsey_mcparseface/context.pbtxt
[[Node: DocumentSource = DocumentSourcebatch_size=32, corpus_name="stdin-conll", task_context="syntaxnet/models/parsey_mcparseface/context.pbtxt", _device="/job:localhost/replica:0/task:0/cpu:0"]]
What could be a possible solution?
Though it's not certain but I think you are not running the shell script from the root directory. Please try running it as per the instructions mentioned here
I hope it helps.

Errors in codeigniter-restserver library

I want to use restful in my ci 3.03 application:
I found this tutplus tutorial
I downloaded codeigniter-restserver-master.zip file and copied Format.php and REST_Controller.php(#version 3.0.0) files into /application/libraries/REST directory
I created control application/controllers/api/Users.php :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
class Users extends REST_Controller
{
//protected $rest_format = 'json';
function users_get()
{
//$users = $this->user_model->get_all();
$filter_username= $this->get('filter_username');
$filter_user_group= $this->get('filter_user_group');
$filter_active= $this->get('filter_active');
$sort= $this->get('sort');
$sort_direction= $this->get('sort_direction');
//, $filter_user_group, $filter_active, $sort, $sort_direction
$users_list = $this->muser->getUsersList(false, ''/*, $filter_username, $filter_user_group, $filter_active, $sort, $sort_direction, ''*/);
echo '<pre>'.count($users_list).'::$users_lists::'.print_r($users_list,true).'</pre>';
if($users_list)
{
$this->response($users, 200);
}
else
{
$this->response(NULL, 404);
}
}
AND RUNNING URL http://local-ci3.com/api/users I got many errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 734
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 734
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 752
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 752
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
Actually I wanted to get some workable library to help me with REST api creation. I think that is preferable way istead of making from zero.
But is this library not workable or does it needs for some fixing? Sorry, what I missed is if this library only for ci 2?
I made search on this forum and found such hint :
I have the same problem when I load both Format.php and
Rest_Controller.php into a controller. After have a quick glance at
Format.php, it appears to be a standalone format conversion helper.
Try to just load Rest_Controller.php and see if your problem goes
away.
I commented line
//require_once("application/libraries/REST/Format.php");
in my controller, but I still get errors like :
Message: Undefined property: Users::$format.
I tried to review code of this library and see that invalid block when data are converted to json format, line 731-757 :
elseif ($data !== NULL)
{
// If the format method exists, call and return the output in that format
if (method_exists($this->format, 'to_' . $this->response->format))
{
// Set the format header
$this->output->set_content_type($this->_supported_formats[$this->response->format], strtolower($this->config->item('charset')));
$output = $this->format->factory($data)->{'to_' . $this->response->format}();
// An array must be parsed as a string, so as not to cause an array to string error
// Json is the most appropriate form for such a datatype
if ($this->response->format === 'array')
{
$output = $this->format->factory($output)->{'to_json'}();
}
}
else
{
// If an array or object, then parse as a json, so as to be a 'string'
if (is_array($data) || is_object($data))
{
$data = $this->format->factory($data)->{'to_json'}();
}
// Format is not supported, so output the raw data as a string
$output = $data;
}
}
If I tried to commented this block, but get error
Message: Array to string conversion
Looks like data are not converted in this case...
Is is possible to fix these errors?
Or can you, please, to tell me advice some codeigniter 3 REST api workable library with similar interface like library above?
Thanks!
I use that lib, work just fine. My suggestion is follow the more relevant installation instruction on github .
you also wrong place the lib file :
Tutorial say :
require(APPPATH'.libraries/REST_Controller.php');
You try :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
No need to include the format because on line 407 the lib will load it. And also good to know on line 404 it will load the configuration (application/config/rest.php) it will be your default configuration, and also you can change it to suit your need.
Please let me know if you still got error using my answer :)

Magento SOAP 2 API Fatal error: Procedure 'login' not present

I am getting: Fatal error: Procedure 'login' not present in /chroot/home/mystore/mystore.com/html/lib/Zend/Soap/Server.php on line 832
This is where the error is coming from
$soap = $this->_getSoap();
ob_start();
if($setRequestException instanceof Exception) {
// Send SOAP fault message if we've catched exception
$soap->fault("Sender", $setRequestException->getMessage());
} else {
try {
$soap->handle($request);
} catch (Exception $e) {
$fault = $this->fault($e);
$soap->fault($fault->faultcode, $fault->faultstring);
Any Ideas on how to fix the error?
I had the same issue, and which I did to fix it was to go to System/Configuration/Magento Core API and set the value WS-I Compliance as 'No'.
I'm working with a WebService which consumes the Magento V2 API, I don't recall if I generate the web reference using this value as 'Yes'; I'm working with a WS C# using VS 2010.
I had similar problem and I did not want to change the API version. Deleting the WSDL cache helped me.
Run this to get the WSDL cache folder:
php -i | grep soap
From the result you can see that the WDSL cache is enabled and stored in /tmp:
soap
soap.wsdl_cache => 1 => 1
soap.wsdl_cache_dir => /tmp => /tmp
soap.wsdl_cache_enabled => 1 => 1
soap.wsdl_cache_limit => 5 => 5
soap.wsdl_cache_ttl => 86400 => 86400
Remove the cache and run it again:
sudo rm -rf /tmp/*
I found the clue in this article - http://artur.ejsmont.org/blog/content/php-soap-error-procedure-xxx-not-present