I am trying to create a NetCDF file using java (unidata library). One of the requirements is to include the _FillValue attribute in all the Variables. I have one of type CHAR, and I can not do it.
The Attribute constructor only accepts Strings or numbers (or arrays of them), not chars. I have tried both of them anyway but the final netcdf does not show the attribute.
Other languages let you do it (we have seen this working in matlab), but I don't know how to do it using java.
I see in the documentation that the _FillValue should be of the same type of the Variable itself but Attribute values does not accept Chars, only String or Numbers
For example: When I try
Nc4Chunking chunker = Nc4ChunkingStrategy.factory(Nc4Chunking.Strategy.standard, 6, true);
NetcdfFileWriter dataFile = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf4_classic, fileName, chunker);
....
Variable varid_scdr = dataFile.addVariable(null, "SCDR", DataType.CHAR, dimsTMS15);
varid_scdr.addAttribute(new Attribute("_FillValue", " "));
....
dataFile.write(varid_scdr, scodData);
dataFile.close();
The resulting netcdf file has no _FillValue, it is not written in the file.
But if I change the attribute name and do this
varid_scdr.addAttribute(new Attribute("FillValue", " "));
the parameter is present in the output file
I have no problems with other data types or other attribute names. I am prety sure that the problem is about the attribute _FillValue for the variable of type Char. I dont know how to write it and I need the _FillValue attribute to be explicity present in the variable attribute list.
********* 5th July 2019 ***********
I realized that the problem is only related to netcdf4 and netcdf4_classic files. So perhaps is about chunking or something like that. If I try it creating netcdf3 files it workis.
Any help about this issue? what am I missing?
I think this is due to bug that has been addressed in the latest version of netcdf-java (v5.0.0). v5.0.0 has been released and is available for download; my hope is that the announcement will go out today.
If you want to be explicit about writing a CHAR valued attribute, one way to to it would be:
String fillValue = " ";
Array charArrayFillValue = ArrayChar.makeFromString(fillValue, 1);
charAttrFillValue = new Attribute("_FillValue", charArrayFillValue);
varid_scdr.addAttribute(charAttrFillValue)
another way would be:
String fillValue = " ";
Array charArrayFillValue = ArrayChar.makeFromString(fillValue, 1);
charAttrFillValue = new Attribute("_FillValue", DataType.CHAR);
charAttrFillValue.setValues(charArrayFillValue);
varid_scdr.addAttribute(charAttrFillValue)
Both of those are a bit verbose, though. I just checked using version 5, and your one liner works:
varid_scdr.addAttribute(new Attribute("_FillValue", " "));
However, if you try to pass in a value for _FillValue that isn't a string of length 1, the netCDF-C library will throw an error. So this:
varid_scdr.addAttribute(new Attribute("_FillValue", "ab"));
will result in:
-36 (NetCDF: Invalid argument) on attribute ':_FillValue = "ab"' on var varid_scdr
netCDF-Java will make sure the string you pass in gets converted to CHARs, but it won't truncate the resulting set of CHARs to fit into the single character limit on the _FillValue attribute.
I have a BDP function that looks like this.
BDP("Glen Ln Equity","NAME_CHINESE_SIMPLIFIED")
It is to update the Chinese name of a security.
I have to translate it to Java blpapi but I am not sure how.
Since this is a BDP function, I think I should use Reference Data Request but you can only specify the ticker and field mnemonic when creating a Reference Data Request. I also know I can use override but to use an override, based on my understanding, I will need a fieldID so that I can set that fieldID's value to be "NAME_CHINESE_SIMPLIFIED".
However, I am not sure what fieldID to use.
What fieldID should I use for the override?
Also, where can I find a list of fieldIDs that can set for overrides?
It should work fine with a reference data request - you don't need to override anything here:
Element security = request.getElement("securities");
security.appendValue("GLEN LN Equity");
Element field = request.getElement("fields");
field.appendValue("NAME_CHINESE_SIMPLIFIED ");
In my elasticsearch I want to get all the indices' name of the cluster. How can I do using java?
I search the internet but there's no much useful information.
You can definitely do it with the following simple Java code:
List<IndexMetaData> indices = client.admin().cluster()
.prepareState().get().getState()
.getMetaData().getIndices();
The list you obtain contains the details on all the indices available in your ES cluster.
You can use:
client.admin().indices().prepareGetIndex().setFeatures().get().getIndices();
Use setFeatures() without parameter to just get index name. Otherwise, other data, such as MAPPINGS and SETTINGS of index, will also be returned by default.
Thanks for #Val's answer. According to your method, I use it in my projects, the code is:
ClusterStateResponse response = transportClient.admin().cluster() .prepareState()
.execute().actionGet();
String[] indices=response.getState().getMetaData().getConcreteAllIndices();
This method can put all the indices name into a String array. The method works.
there's another method I think but not tried:
ImmutableOpenMap<String, MappingMetaData> mappings = node.client().admin().cluster()
.prepareState().execute().actionGet().getState().getMetaData().getIndices().
then, we can get the keys of mappings to get all the indices.
Thanks again!
I am tring to get a list of groups a user is a member of, currently I can get most attributes as follows
CustomLdapUserDetails.Essence essence = new CustomLdapUserDetails.Essence();
essence.setDn(dn);
Object passwordValue = ctx.getObjectAttribute(passwordAttributeName);
String givennameValue = (String)ctx.getObjectAttribute("givenname");
String snValue = (String)ctx.getObjectAttribute("sn");
String titleValue = (String)ctx.getObjectAttribute("title");
essence.setFirstname(givennameValue);
essence.setLastname(snValue);
but I cannot figure out how to get the memberOf attribute. If I output the whole DirContextOperations as a String I get the following
org.springframework.ldap.core.DirContextAdapter: dn=uid=emp123 {rdn=uid=emp123,
whenCreated=20110816063203.0Z,
objectCategory=CN=fompanyPerson,CN=Schema,CN=Configuration,CN={9F17F445-56C4-42D9-
B7C6-B630FFEA7F07}, badPwdCount=0, otherTelephone=123-456789, businessUnit=IREIRE BU,
ntAccount=DMN1\emp123, managerID=emp987, objectGUID=5?
?e6A??????/, mail=emp123#somewhere.com, uid=emp123, companyWorkRelationship=EMP,
memberOf[0]=CN=ABC IREIRE,OU=AutoGroups,DC=entdir,DC=gtn,DC=com,
memberOf[1]=CN=azgEntJazzUsers,OU=AutoGroups,DC=entdir,DC=gtn,DC=com, companySite=DBL,
companyCostCenter=91827, companyBusinessGroup=IREIRE BG, ntDomain=DMN1, instanceType=4,
corpID=emp123, objectSid= I???&?C?k?J???????, st=XX, badPasswordTime=0, vdejoindn=P-
ENTDIRXXX-1:uid=emp123,DC=entdirXXX,DC=gtn,DC=com, companySourceSystem=C-WORKSYSTEM,
objectClass[0]=top, objectClass[1]=person, objectClass[2]=organizationalPerson,
objectClass[3]=user, objectClass[4]=inetOrgPerson, objectClass[5]=fompanyPerson,
company=ABC DEV, name=emp123, sn=Smith, exchangeAlias=emp123, telephoneNumber=1-987-6543,
ntDomainRelative=DMN1, uSNChanged=999111, physicalDeliveryOfficeName=DXI,
ntAccountRelative=DMN1\emp123, cn=Smith, John, exchangeServer=someServer,
documentumUserName=Smith JOHN emp123, title=SOFTWARE ENGINEER/DEVELOPER,
otherCertMailbox=emp123#xyz.somewhere.com, msDS-UserAccountDisabled=TRUE,
managerName=Bloggs, Joe, givenName=John, uSNCreated=18418957, displayName=Smith, John,
pwdLastSet=629579433359695509, fompanyPersonStatus=A, whenChanged=20120266070711.0Z,
o=IREIRE BU, distinguishedName=uid=emp123,DC=entdirXXX,DC=gtn,DC=com, eDARevoke=N,
division=SEF-GL , manager=uid=emp987,DC=entdirXXX,DC=gtn,DC=com,
exchangeDirectory=SMXZG1DB, samAccountName=emp123, sametimeServer=cvxcluster}
What I need to get is the CN value of each memberOf into an array of Strings, I have tried:
ctx.getObjectAttribute("memberOf[1]"))
ctx.getObjectAttribute("memberOf"))
ctx.getObjectAttribute("memberOf=CN"))
I've seen examples online of setting but I could not find any examples of getting, is it really that much more complex then getting the other Attributes?
Any advice would be greatly appreciated
You probably only miss one "s" from the end. Try:
ctx.getObjectAttributes("memberOf")
The javadoc clarifies what's the difference between the singular and plural form method. (The former only returns the first value even if the given attribute is multi-valued.)
Are you using Active Directory as your LDAP provider?
Not all LDAP providers have a memberOF attribute on the user.
The proper method to get groups of a user would be to search groups for a filter like:
(member=<fully distinguished name of user>)
Returning attribute "CN".
I wanted to add a new synset to Wordnet using the extjwnl library. In order to do this, I wrote the following sample code. After saving, I observe that the new synonym and word do get added, but the semantic pointer created (which identifies the hyponymy relation) is not saved. How do I relate the pointer to the dictionary?
JWNL.initialize(new FileInputStream(propsFile));
Dictionary dictionary = Dictionary.getInstance();
Iterator<Synset> synsets = dictionary.getSynsetIterator(POS.NOUN);
dictionary.edit();
Synset newSynset = new Synset(dictionary, POS.NOUN);
IndexWord newWord = new IndexWord(dictionary, "hublabooboo", POS.NOUN, newSynset);
Synset topmostSynset = synsets.next();
Pointer newPointer = new Pointer(PointerType.HYPONYM, topmostSynset, newSynset);
dictionary.save();
I'd suggest you add pointer to the synset's list of pointers:
topmostSynset.getPointers().add(newPointer);
If the pointer is symmetric (like hypernym, which has a mirror one: hyponym), and dictionary.getManageSymmetricPointers() then the reverse pointer (e.g. hyponym) is added automatically.
By the way, by this code Synset topmostSynset = synsets.next(); it looks like you infer that the first returned synset from the synset iterator is the "entity" one. But this is not guaranteed anywhere. This is dictionary-dependent: might work for file-based, but most likely won't for map-based and unpredictable for database-based.
Source : SourceForge