cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Remove a constraint without the GUI

t.masse
1-Newbie

Remove a constraint without the GUI

Hello all,

I want to remove a SingleValuedConstraint on a soft type. By the GUI this can be done easily but i don't find the way to do it without the GUI.

Any ideas ?

1 REPLY 1
MatthewKnight
4-Participant
(To:t.masse)

I came up with this, originally to set a discrete set, but I only got as far as updating the set when the constraint already existed. It might be overly complicated but it should help.

public static WTTypeDefinition setDiscreteSet(WTTypeDefinition td, String attribute, DiscreteSet ds) throws WTException {

try {

Locale locale = SessionHelper.getLocale();

TypeDefinitionDefaultView tddv = getTypeDefinitionDefaultView(td);

TypeDefinitionNodeView tdnv = getTypeDefinitionNodeView(tddv);

tdnv = TypeAdminHelper.service.checkoutTypeNode(tdnv, locale);

tddv = getTypeDefinitionDefaultView(tdnv);

AttributeContainer ac = tddv.getAttributeContainer();

ConstraintContainer cc = tddv.getConstraintContainer();

AttributeIdentifier ais[] = ac.getAttributeIdentifiers(attribute);

boolean set = false;

if(ais != null) {

for(int aisIndex = 0; aisIndex < ais.length; aisIndex++) {

AttributeIdentifier ai = ais[aisIndex];

ConstraintIdentifier cis[] = cc.getConstraintIdentifiers(ac, ai, ConstraintContainer.BOTH);

if(cis != null) {

for(int cisIndex = 0; cisIndex < cis.length; cisIndex++) {

ConstraintIdentifier ci = cis[cisIndex];

//if(ci.getDefinitionIdentifier().toString().endsWith(DiscreteSet)

try {

if(DiscreteSetConstraint.class.isAssignableFrom(Class.forName(ci.getEnforcementRuleClassname()))) {

ConstraintData cd = new ConstraintData(ds, ai.getDefinitionIdentifier());

cc.remove(ci);

cc.put(ci, cd);

set = true;

}

} catch (ClassNotFoundException e) {

throw new WTException(e);

}

}

}

}

}

if(set == false) {

//I don't know how to construct an attributeidentifier/constraintidentifier.

//For now, you can only replace a discreteset constraint, not create a new one.

//com.ptc.core.meta.common.AttributeTypeIdentifier ati;

//ConstraintData cd = new ConstraintData(ds, ai.getDefinitionIdentifier());

//cc.put(ci, cd);

throw new WTException("Unable to update discrete set. First create a discrete set through the gui, then we can update.");

}

tddv.setConstraintContainer(cc);

tddv = TypeAdminHelper.service.updateTypeDefDefaultView(tddv, locale);

tdnv = TypeAdminHelper.service.checkinTypeNode(tdnv, locale);

return td;

} catch(Exception e) {

throw new WTException(e);

}

}

Announcements


Top Tags