NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package ext.wvs;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;
import java.util.StringTokenizer;

import javax.el.PropertyNotFoundException;

import org.apache.commons.lang.StringUtils;

import wt.dataops.containermove.ContainerMoveHelper;
import wt.fc.PagingQueryResult;
import wt.fc.PagingSessionHelper;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.WTObject;
import wt.fc.collections.WTArrayList;
import wt.fc.collections.WTList;
import wt.fc.collections.WTValuedHashMap;
import wt.fc.collections.WTValuedMap;
import wt.folder.Cabinet;
import wt.folder.Folder;
import wt.folder.FolderHelper;
import wt.inf.container.ContainerSpec;
import wt.inf.container.WTContainer;
import wt.inf.container.WTContainerHelper;
import wt.inf.container.WTContainerRef;
import wt.part.WTPart;
import wt.pds.StatementSpec;
import wt.query.BasicPageableQuerySpec;
import wt.query.ClassAttribute;
import wt.query.OrderBy;
import wt.query.PageableQuerySpec;
import wt.query.PagingSessionSpec;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.representation.Representable;
import wt.util.WTException;
import wt.vc.Iterated;
import wt.vc.VersionIdentifier;
import wt.vc.Versioned;

import com.infoengine.messaging.ConMetaData;
import com.ptc.core.meta.common.TypeIdentifier;
import com.ptc.core.meta.server.TypeIdentifierUtility;
import com.ptc.wvs.server.schedule.ScheduleJobs;

class CustomJobProperties {
InputStream inputStream;

public Properties getPropValues() throws IOException {
Properties prop = new Properties();

try {
String propFileName = "job_config.properties";

inputStream = CustomJobs.class.getResourceAsStream(propFileName);

if (inputStream != null){
prop.load(inputStream);
} else {
throw new FileNotFoundException();
}
}
catch (Exception e) {
// TODO: handle exception
}
finally {
inputStream.close();
}

return prop;
}
}

public class CustomJobs extends ScheduleJobs {

private static final String MILITARE = "ITML";
private static final String DUALE = "EUDUL";
private static final String NECT = "NECT";

public static WTList myCustomJob() {
WTList wtl = new WTArrayList();
CustomJobProperties customJobProperties = new CustomJobProperties();
Properties properties = null;
try {
properties = customJobProperties.getPropValues();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

try {
QuerySpec qs = new QuerySpec(WTPart.class);
WTContainerRef cr = ScheduleJobs.getCurrentContainer();
if (cr != null) {
ContainerSpec cs = new ContainerSpec();
cs.addSearchContainer(cr);
qs.setAdvancedQueryEnabled(true);
qs.appendWhere(
WTContainerHelper.getWhereContainerIn(cs, new Class[]
{WTPart.class}),
new int[]{0});
}
if (cr != null) qs.appendAnd();
qs.appendWhere(new SearchCondition(WTPart.class,
Iterated.LATEST_ITERATION,
SearchCondition.IS_TRUE),
new int[]{0});
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTPart.class,
WTPart.NUMBER,
SearchCondition.EQUAL, "0000000001"),
new int[]{0});

Representable doc = null;
int offset = 0;
BasicPageableQuerySpec bpqs = new BasicPageableQuerySpec();
bpqs.setPrimaryStatement(qs);
bpqs.setOffset(offset);
bpqs.setRange(1000);
PagingQueryResult qr =
(PagingQueryResult)PersistenceHelper.manager.find(bpqs);
long sessionId = qr.getSessionId();
int total = qr.getTotalSize();

while (true) {
while (qr.hasMoreElements()) {
//WTContainer wtContainer = findObject(WTContainer.NAME, "GENERIC_COMPUTER");
//WTContainer containeDest = findObject(WTContainer.NAME, "COMPUTER");

WTPart parte = (WTPart)((Object[])qr.nextElement())[0];
String jurisdiction = "NECT";

if (checkifNeedToChangeContext(parte.getContainer(), "COMPUTER", jurisdiction, properties)) {

String typeName = getObjectType(parte);

WTContainer wtContainerDest = findObject(WTContainer.NAME, getContainerNameFromProductAndJuristiction("COMPUTER",jurisdiction,properties));

ArrayList<String> listStructure = extractFolderStructure(parte.getContainer().getDefaultCabinet(), parte.getName(), parte.getFolderPath(), typeName, properties);

Folder folder = getFolderDest(wtContainerDest, listStructure);

WTValuedMap map = new WTValuedHashMap();
map.put(parte, folder);
ContainerMoveHelper.service.moveAllVersions(map);
}
}

offset += qr.size();
if (offset >= total) break;

PageableQuerySpec pqs = new PagingSessionSpec(sessionId);
pqs.setOffset(offset);
pqs.setRange(1000);
qr = (PagingQueryResult)PersistenceHelper.manager.find(pqs);
}
if (sessionId > 0) PagingSessionHelper.closePagingSession(sessionId);
} catch(Exception e) {e.printStackTrace(); wtl = new WTArrayList ();}

return wtl;
}

private static WTContainer findObject(String parameter, String value) throws WTException{
if(value==null || "".equals(value)) return null;
QuerySpec qs = new QuerySpec(WTContainer.class);
qs.appendWhere(new SearchCondition(WTContainer.class, parameter, SearchCondition.EQUAL, value), new int[]{0});
if(Iterated.class.isAssignableFrom(WTContainer.class)){
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTContainer.class, Iterated.LATEST_ITERATION, SearchCondition.IS_TRUE), new int[]{0});
}
if(Versioned.class.isAssignableFrom(WTContainer.class)){
qs.appendOrderBy(new OrderBy(new ClassAttribute(WTContainer.class, Versioned.VERSION_IDENTIFIER+"."+VersionIdentifier.VERSIONSORTID), true), new int[]{0});
}
StatementSpec sSpec=qs;
QueryResult qr = PersistenceHelper.manager.find(sSpec);
if(qr.size() > 0) return (WTContainer)(qr.nextElement());
return null;
}

private static ArrayList<String> extractFolderStructure(Cabinet cabinet, String itemName, String folderDest, String objectType, Properties prop){
ArrayList<String> folderStructureDest = new ArrayList<String>();
String rootFolder = prop.getProperty(objectType+".root.folder");
if (rootFolder!=null && StringUtils.isNotBlank(rootFolder)){
folderStructureDest.add(rootFolder);
}

StringTokenizer tokenizer = new StringTokenizer(folderDest, "/");
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (cabinet.getFolderPath().replaceAll("/", "").equals(token) ||
itemName.equals(token)){
continue;
}
else {
if (!token.equalsIgnoreCase(rootFolder))
folderStructureDest.add(token);
}
}

return folderStructureDest;
}

private static boolean checkFolderExists(WTContainer container, String folderDest){
try {
FolderHelper.service.getFolder(container.getDefaultCabinet().getFolderPath()+folderDest, WTContainerRef.newWTContainerRef(container));
} catch (WTException e) {
return false;
}

return true;
}

private static Folder getFolderDest(WTContainer containerDest, ArrayList<String> folderPaths) throws WTException{
String folderToCheck = "";
for (String folder : folderPaths){
folderToCheck += "/"+folder;
if (checkFolderExists(containerDest, folderToCheck)){
continue;
}
else {
String folderToCreate = containerDest.getDefaultCabinet().getFolderPath()+folderToCheck;
FolderHelper.service.createSubFolder(folderToCreate, WTContainerRef.newWTContainerRef(containerDest));
}
}

return FolderHelper.service.getFolder(containerDest.getDefaultCabinet().getFolderPath()+folderToCheck, WTContainerRef.newWTContainerRef(containerDest));
}

private static boolean checkifNeedToChangeContext(WTContainer container, String productName, String jurisdition, Properties properties) throws PropertyNotFoundException {
String containerAsIsName = container.getName();

String containerJurisdition = properties.getProperty("container.name."+jurisdition);

if (containerJurisdition == null)
throw new PropertyNotFoundException("Property container.name." + jurisdition + " non trovata. Configurarla nel file ...");
else if (StringUtils.isBlank(containerJurisdition) && containerAsIsName.equalsIgnoreCase(productName))
return false;
else if (StringUtils.isNotBlank(containerJurisdition) && containerAsIsName.contains(productName) && containerAsIsName.contains(jurisdition))
return false;
else
return true;
}

private static String getContainerNameFromProductAndJuristiction(String product, String jurisdition, Properties prop) {
String containerJurisditionName = prop.getProperty("container.name."+jurisdition);

if (containerJurisditionName == null)
throw new PropertyNotFoundException("Property container.name." + jurisdition + " non trovata. Configurarla nel file ...");

if (StringUtils.isBlank(containerJurisditionName)) {
return product;
}
else {
return product+"-"+containerJurisditionName;
}
}

public static String getObjectType(WTObject wtObject) {
TypeIdentifier tid = TypeIdentifierUtility.getTypeIdentifier(wtObject);
String fullTypeName = tid.getTypename();
String[] fullTypeNameSplitted = StringUtils.split(fullTypeName,".");
String typeName = fullTypeNameSplitted[fullTypeNameSplitted.length-1];

return typeName;
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.