新しい投稿

検索

記事
· 2024年12月5日 1m read

How to raise a custom error

InterSystems FAQ rubric

If you want to raise an arbitrary custom error in a TRY block, you can pass an exception with a throw as follows. In the following example, a custom error is raised if Stcount is less than 1.

Class User.Test
{

ClassMethod ExceptionTest()
 {
    try
    {
      // : some codes
      if (Stcount<1) {
          throw ##class(%Exception.General).%New("User-defined error", "5001", "location", "Data at location error")
          // User-created errors are 5001 and above
      }
    }
    catch ex
    {
      write "Errors #", ex.Code, ": ", ex.Name, " : ", ex.Location, " ", ex.Data
      return
    }
 }
}

In the above example, if Stcount is less than 1, an error like the following will be output:

USER>do ##class(User.Test).ExceptionTest()
Error #5001: User-defined error: Data at location error

For more information, see the following documentation:
ObjectScript command _THROW

If you want to create an arbitrary status code, do the following:

USER>set st = ##class(%SYSTEM.Status).Error(5001,"This is a user-defined error")

USER>zwrite st
st="0 "_$lb($lb(5001,"This is a user-defined error",,,,,,,,$lb(,"USER",$lb("e^zError+1^%SYSTEM.Status.1^1","e^^^0"))))/* Error #5001: This is a user-defined error */
USER>do $SYSTEM.Status.DisplayError(st)

Error #5001: This is a user-defined error
ディスカッション (0)0
続けるにはログインするか新規登録を行ってください
記事
· 2024年12月5日 1m read

QuinielaML - Predicción de la 27ª jornada de la Quiniela

¿Listos para una nueva jornada de la Quiniela? Esta jornada un día antes de lo habitual ya que el cierre de la jornada será el viernes y no el sábado como habitualmente. 

Esta jornada se compone de los partidos de la 16ª jornada de Primera División y la 18ª de Segunda División, veamos los partidos que forman parte de la misma:

Esta es la predicción para Primera División:

Y aquí tenemos la Segunda División:

Aquí tenemos la Quiniela de la jornada:

¡Suerte a todos esta jornada!

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
記事
· 2024年12月5日 3m read

Gateway de Linguagem externa Java

Se vocês gostam de Java e têm um ecossistema Java ativo no trabalho e precisam incorporar IRIS, isso não é um problema. A Gateway de Linguagem Externa de Java fará isso sem complicações, ou quase. Essa gateway serve como ponte entre Java e ObjectScript no IRIS. Vocês podem criar objetos de classes Java no IRIS e chamar seus métodos. Só precisam de um arquivo JAR para fazer isso.

Connection diagram: proxy object <-> Gateway object <-> TCP/IP <-> External server <-> target object

A primeira coisa que vocês devem fazer é configurar o ambiente. Para começar a usar a Gateway de Java, certifiquem-se de ter o seguinte:

  1. InterSystems IRIS: Instalado e funcionando.  
  2. Java Development Kit (JDK): Instalado e configurado

O segundo requisito pode parecer simples, já que vocês já usam Java no trabalho, mas não é. Devido a essa questão, descobriu-se que vocês precisam usar a versão 11 do JDK no máximo. Isso significa que vocês devem mudar a versão no seu IDE, o que pode causar bastante complicações

O próximo passo é verificar se tudo está funcionando e tentar instanciar um objeto de uma classe do sistema Java. Para isso, é necessário iniciar uma conexão, criar um objeto proxy e chamar um método. Embora possa parecer que se requer uma grande quantidade de código, na realidade se resume a uma única linha:

write $system.external.getJavaGateway().new("java.util.Date").toString()

Isso imprimirá a data e hora atual na tela.

Para ir além, podemos criar nossa própria classe em Java:


public class Dish {
	private String name;
	private String description;
	private String category;
	private Float price;
	private String currency;
	private Integer calories;
	
	public void setName(String name) {
		this.name = name;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public void setPrice(Float price) {
		this.price = price;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public void setCalories(Integer calories) {
		this.calories = calories;
	}
	
	public String describe() {
		return "The dish "+this.name+" costs "+this.price.toString()+
				this.currency+" and contains "+this.calories+" calories!";
	}
}

e chamar seus métodos do ObjectScript:

 set javaGate = $SYSTEM.external.getJavaGateway()
 do javaGate.addToPath("D:\Temp\GatewayTest.jar")
 set dish = javaGate.new("Dish")
 do dish.setCalories(1000)
 do dish.setCategory("salad")
 do dish.setCurrency("GBP")
 do dish.setDescription("Very tasty greek salad")
 do dish.setName("Greek salad")
 do dish.setPrice(15.2)
 write dish.describe()

Como resultado, obteremos uma string com a descrição do prato criado:

The dish Greek salad costs 15.2GBP and contains 1000 calories!

Em Português: O prato Salada Grega custa 15,2 GBP e contém 1000 calorias!

De qualquer forma, aprendam mais sobre o uso das Gateways na Documentação e boa sorte implementando esse conhecimento em seus projetos!

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
ダイジェスト
· 2024年12月5日

Participate in the InterSystems "Bringing Ideas to Reality" Contest

Dear Community member,

We'd like to invite you to join our next contest dedicated to creating useful tools to make your fellow developers' lives easier: 

🏆 Bringing Ideas to Reality Contest 🏆

Submit an application that implements an idea from the InterSystems Ideas Portal that has statuses Community Opportunity or Future Consideration.

Duration: December 2 - 22, 2024

Prize pool: $14,000

Don't miss this amazing chance to challenge yourself, work alongside other developers, and earn fantastic prizes. Spread the word and invite your friends and colleagues to take part as well!

We’re excited to see your innovative solutions!

>> Full contest details here.

We're looking forward to your entries 😉

質問
· 2024年12月5日

Creating an Operation to Connect to an OAuth 2.0 Server

I have created an OAuth Client and have created the credentials etc successfully.

I have tested using the curl command and have received the token back from the Server using the terminal.

I now need to create an Operation to use my client credentials to connect to the Server and receive the token back.

What adapter would I use as I am unable to link my client credentials and secret  - currently  I am using the EnsLib.HTTP.OutboundAdapter
 but I am not sure if this is the correct.

2 Comments
ディスカッション (2)2
続けるにはログインするか新規登録を行ってください