How to set my computerId into primary key? - grails

Here's my code in domain. I wanted to set my computerId into a primary key. But still display on my table(index). Thanks
package com.data
class ComputerInformation {
String computerId;
String computerName;
String status;
String location;
String serial;
String monitorSerial;
String keyboardSerial;
String mouseSerial;
String cpuSerial;
String avrSerial;
String harddiskSerial;
static constraints = {
computerId(unique:true)
computerName(blank:false)
status(blank:false)
location(blank:false)
serial(blank:false)
monitorSerial(blank:false)
keyboardSerial(blank:false)
mouseSerial(blank:false)
cpuSerial(blank:false)
avrSerial(blank:false)
harddiskSerial(blank:false)
}
}

use like this,
static mapping = {
id name: 'computerId'
}

Maybe instead of changing PK, return id as a computerId variable?
package com.data
class ComputerInformation {
String computerName;
String status;
String location;
String serial;
String monitorSerial;
String keyboardSerial;
String mouseSerial;
String cpuSerial;
String avrSerial;
String harddiskSerial;
static constraints = {
computerName(blank:false)
status(blank:false)
location(blank:false)
serial(blank:false)
monitorSerial(blank:false)
keyboardSerial(blank:false)
mouseSerial(blank:false)
cpuSerial(blank:false)
avrSerial(blank:false)
harddiskSerial(blank:false)
}
def getComputerId(){
return id
}
}
Moreover if you need computerId as a String, you can change getComputerId function to:
String getComputerId(){
return id.toString()
}

Related

How to override the default encrypted property prefix/suffix?

Jasypt expects encrypted properties to be wrapped with "ENC(...)".
I'm looking for a way to override the default jasypt encrypted property prefix and suffix with a custom ones like "secure[...]".
Is there a way to achieve this?
If you use pure jasypt library it is required to write your own version of existing EncryptableProperties as default one supports only ENC( as prefix and ) as suffix.
public class EncryptableProperties extends Properties {
private final String prefix;
private final String suffix;
private final StringEncryptor encryptor;
public EncryptableProperties(final Properties defaults, final StringEncryptor encryptor,
final String prefix, final String suffix) {
super(defaults);
this.encryptor = encryptor;
this.prefix = prefix;
this.suffix = suffix;
}
public EncryptableProperties(final Properties defaults, final StringEncryptor encryptor){
this(defaults,encryptor,"ENC(", ")");
}
#Override
public String getProperty(String key) {
String value = super.getProperty(key);
return decode(value);
}
private String decode(String value) {
if (value == null) {
return value;
}
String decryptedValue = value;
if (value.startsWith(prefix) && value.endsWith(suffix)) {
int start = prefix.length();
int end = value.length() - suffix.length();
String encryptedValue = value.substring(start, end);
decryptedValue = encryptor.decrypt(encryptedValue);
}
return decryptedValue;
}
}
Usage:
Properties encryptableProperties = new EncryptableProperties(properties,stringEncryptor,"CUSTOM_PREFIX(",")");
If you use spring boot integration
You could do this by using following two properties
jasypt.encryptor.property.prefix
jasypt.encryptor.property.suffix
Default one is:
jasypt.encryptor.property.prefix=ENC(
jasypt.encryptor.property.suffix=)
These properties are available with following library
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot</artifactId>
<version>2.0.0</version>
</dependency>

How do you change the value of a List[index].fieldname flutter?

How do you change the value of a List[index].fieldname flutter?
class Person {
String firstName;
String lastName;
}
//assuming contacts is a List<Person>
contacts[index].firstName = 'Tony';

How to create a detailed Report with MQL4?

In MetaTrader Terminal 4, there is an option to create a detailed Report. You get results of your account history in an html-format.
I am searching for a function which generates this html-file automatically.
Observation:
As of 2018-02 there has not been any such auto-generate Report feature in the MQL4 language syntax available.
Solution:
One may resort to use a custom-defined code, enjoying an ability to launch it in either of OnDeinit() + OnTester() handlers.
This is my solution i have build. The method creates two csv, named them with date and SYMBOL or date and ACCOUNT. In ACCOUNT are all trades. In SYMBOL just the symbol trades. After create the csv i import them automatically via java into a MySQL database.
void ExportHistory()
{
int symbolHandle;
symbolHandle=FileOpen(Historyfile(Symbol()),FILE_SHARE_READ|FILE_TXT|FILE_WRITE);
if(symbolHandle>0)
{
for(int index=0;index<OrdersHistoryTotal();index++)
{
if(OrderSelect(index,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol())
{
string ticket=IntegerToString(OrderTicket());
string openTime=TimeToString(OrderOpenTime(),TIME_DATE|TIME_SECONDS);
string type=EnumToString((ENUM_ORDER_TYPE)OrderType());
string size=DoubleToString(OrderLots(),2);
string item=OrderSymbol();
string openPrice=DoubleToString(OrderOpenPrice(),Digits);
string stoploss=DoubleToString(OrderStopLoss(),Digits);
string takeprofit=DoubleToString(OrderTakeProfit(),Digits);
string closeTime=TimeToString(OrderCloseTime(),TIME_DATE|TIME_SECONDS);
string closePrice=DoubleToString(OrderClosePrice(),Digits);
string swap=DoubleToString(OrderSwap(),2);
string profit=DoubleToString(OrderProfit(),2);
string msg=ticket+";"+openTime+";"+type+";"+size+";"+item+";"+openPrice+";"+stoploss+";"+takeprofit+";"+closeTime+";"+closePrice+";"+swap+";"+profit;
FileWrite(symbolHandle,msg);
}
}
}
FileClose(symbolHandle);
}
int mainHandle;
mainHandle=FileOpen(Historyfile("ACCOUNT"),FILE_SHARE_READ|FILE_TXT|FILE_WRITE);
if(mainHandle>0)
{
for(int index=0;index<OrdersHistoryTotal();index++)
{
if(OrderSelect(index,SELECT_BY_POS,MODE_HISTORY))
{
string ticket=IntegerToString(OrderTicket());
string openTime=TimeToString(OrderOpenTime(),TIME_DATE|TIME_SECONDS);
string type=EnumToString((ENUM_ORDER_TYPE)OrderType());
string size=DoubleToString(OrderLots(),2);
string item=OrderSymbol();
string openPrice=DoubleToString(OrderOpenPrice(),Digits);
string stoploss=DoubleToString(OrderStopLoss(),Digits);
string takeprofit=DoubleToString(OrderTakeProfit(),Digits);
string closeTime=TimeToString(OrderCloseTime(),TIME_DATE|TIME_SECONDS);
string closePrice=DoubleToString(OrderClosePrice(),Digits);
string swap=DoubleToString(OrderSwap(),2);
string profit=DoubleToString(OrderProfit(),2);
string msg=ticket+";"+openTime+";"+type+";"+size+";"+item+";"+openPrice+";"+stoploss+";"+takeprofit+";"+closeTime+";"+closePrice+";"+swap+";"+profit;
FileWrite(mainHandle,msg);
}
}
FileClose(mainHandle);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string Historyfile(string type)
{
string date=TimeToString(TimeCurrent(),TIME_DATE);
StringReplace(date,".","");
return date+"_"+type+".csv";
}
//+------------------------------------------------------------------+

How to get the Public key in string format of a SSL certificate in ios

I can get the public key of SSL certificate using SecTrustCopyPublicKey. But how can get the Public key in string format?
if you want to save public key ec curve name, you can use this function:
string public_key_ec_curve_name(X509 *x509)
{
EVP_PKEY *pkey = X509_get_pubkey(x509);
int key_type = EVP_PKEY_type(pkey->type);
if (key_type == EVP_PKEY_EC)
{
cont EC_GROUP* group = EC_KEY_GET0_group(pkey->pkey.ec);
int name = (group != NULL) ? EC_GROUP_get_curve_name(group) : 0;
return name ? OBJ_nid2sn(name) : ";
}
return "";
}
it saves the public ec curve name in string format.

How to implement Data model using swift? (java -> swift)

in Java the model looks like this:
public class Model {
private String nameLast = "";
private String nameFirst = "";
private String namePrefix = "";
private String nameSecond = "";
private String nameNick = "";
private String nameSuffix = "";
Model() {
}
public Model(String nameFirst, String nameSecond, String nameLast, String namePrefix, String nameSuffix, String nameNick) {
this.nameFirst = nameFirst;
this.nameSecond = nameSecond;
this.nameLast = nameLast;
this.namePrefix = namePrefix;
this.nameSuffix = nameSuffix;
this.nameNick = nameNick;
}
public String getNameLast() {
return nameLast;
}
public void setNameLast(String nameLast) {
this.nameLast = nameLast;
}
public String getNameFirst() {
return nameFirst;
}
public void setNameFirst(String nameFirst) {
this.nameFirst = nameFirst;
}
public String getNamePrefix() {
return namePrefix;
}
public void setNamePrefix(String namePrefix) {
this.namePrefix = namePrefix;
}
....
}
In Swift there is no access control (private/public) and the setter/getters are only for computed properties.
How should I implement this in swift?
Should I use a struct?
Perhaps I have to use willSet and didSet - I need your help ;)
You can make it really simple in Swift. There are many similar parts in Swift.
class Model : NSObject{
var nameFirst = ""
var nameSecond = ""
var nameLast = ""
init(nameFirst:String, nameSecond:String, nameLast:String){
self.nameFirst = nameFirst
self.nameSecond = nameSecond
self.nameLast = nameLast
}
}
Then, instead of using a get or a set method, you can simply use the variable to set and get the values of the variable:
var mod = Model(nameFirst: "hey", nameSecond: "what's", nameLast: "up")
println(mod.nameLast)
While didSet and willSet are useful for counting, how many times a method was set, you don't need it in this case. Also in your case you dont need to set get for these variables like that:
var value : Int {
get { return 10 }
}

Resources